|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int asd;
cout<<"Bitte Sekundenzahl angeben! Nach dieser Angabe wird der PC Heruntergefahren!\n\n";
cin>>asd;
string str= "start Shutdown.exe -s -t ";
str += asd;
system(str.c_str());
system("PAUSE > NUL");
return 0;
}
|
TRING zu arbeiten, funktioniert aber irgendwie auch nicht.
![]()
Source code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16#include <cstdlib> #include <string> #include <iostream> using namespace std; int main(int argc, char *argv[]) { int asd; cout<<"Bitte Sekundenzahl angeben! Nach dieser Angabe wird der PC Heruntergefahren!\n\n"; cin>>asd; string str= "start Shutdown.exe -s -t "; str += asd; system(str.c_str()); system("PAUSE > NUL"); return 0; }
Ich hab da jetzt mal versucht mit nem STD:TRING zu arbeiten, funktioniert aber irgendwie auch nicht.
Wäre Dankbar, wenn jemand eine funktionierende Variante postet.
MfG: eriX
|
|
XML Code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include <iostream> #include <cstdio> using namespace std; int main() { cout << "Befehl: "; char buf[256]; cin >> buf; if(system(buf) == -1) cout << "FEHLER" << endl; return 0; } |
|
|
C/C++ Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 |
#include <iostream> #include <cstdio> #include <string>//oder war es string.h k.A^^ int main() { std::cout << "Befehl: "; string buf,string vorgabe="shutdown "; std::cin >> buf; System(vorgabe+buf); return 0; } |
![]()
C/C++ Quellcode
1 2 3 4 5 6 7 8 9 10 11 12 #include <iostream> #include <cstdio> #include <string>//oder war es string.h k.A^^ int main() { std::cout << "Befehl: "; string buf,string vorgabe="shutdown.EXE "; std::cin >> buf; System(vorgabe+buf ... .c_str()); return 0; }
|
|
C/C++ Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include <iostream> #include <cstdio> #include <string> int main() { std::cout << "Befehl: "; std::string buf, vorgabe="shutdown.EXE "; std::cin >> buf; vorgabe.append(buf); system(vorgabe.c_str()); return 0; } |
|
|
C/C++ Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include <iostream> #include <cstdio> #include <string> int main() { std::cout << "Befehl: "; std::string buf, vorgabe="shutdown "; // vor dem letzten ": Space oder nicht Space, das ist hier die Frage ;) std::cin >> buf; vorgabe.append(buf); std::system(vorgabe.c_str()); // wenn schon STL, dann ... return 0; } |

This post has been edited 5 times, last edit by "bcc-fan" (Jul 19th 2008, 5:12pm)
|
|
C/C++ Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include <iostream> #include <cstdio> #include <string> int main() { std::cout << "Befehl: "; std::string buf, vorgabe="shutdown.exe -s -f -t "; std::cin >> buf; vorgabe.append(buf); std::system(vorgabe.c_str()); return 0; } |
|
|
C/C++ Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#include <cstdlib> #include <iostream> using namespace std; bool checkIfInt(const char* text) { for (int i = 0; i<strlen(text); ++i) { if (!isdigit(text[i])) { return false; } } return true; } int main(int argc, char *argv[]) { string asd; cout<<"Bitte Sekundenzahl angeben! Nach dieser Angabe wird der PC Heruntergefahren!\n\n"; cin>>asd; if (checkIfInt(asd.c_str())) { string str= "start shutdown.exe -s -t "; str += asd; system((str).c_str()); } else { cout<<"Der eingegebene Text ist keine Zahl. Der PC wird nicht heruntergefahren.\n"; } system("PAUSE > NUL"); return 0; } |
|
|
C/C++ Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include <iostream> #include <cstdio> #include <string> int main() { std::cout << "Befehl: "; std::string vorgabe="start shutdown.exe -s -t "; int buf; std::cin >> buf; char sBuf[128]; sprintf (sBuf, "%u", buf * 60); vorgabe.append (sBuf); std::system(vorgabe.c_str()); return 0; } |