On Windows, use & or && between your commands. The first (single-ampersand) performs each given command no matter what. The second (double-ampersand) only performs up-to any error.
The system() command takes a const char*, so use s.c_str().
Yes, i know about people messing wiht my drive exc... I know about hacking a crap but i don't care about that. If I was worried about someone messing with my drives, i wouldn't allow the user to send input to my command prompt. I'm not an idiot. I understand this... I'm doing this for educational purposes
EDIT: Oh and when i said multiple commands, i meant how would i scan for something like this
shutdown -h
like accept the input shutdown and then accept he parrameter -s or -h
shutdown -s
exc... So how would i scan for another input using a space as a separator? I know you can do this in java so this has got to be possible in c++
The correct response is either something like, "Thanks for the input about the system() function. I'll keep that in mind." or to ignore it altogether and focus on what you specifically want. Becoming defensive when you receive advice makes it difficult to receive future advice. You were demonstrating something very dangerous, even if you know better, so it is not unreasonable to have been advised against it.
Your question was not clear. If I understand you correctly now, I think you are trying to give the user the option to enter more than one command with a single input string.
Do it the same way the system shell does it -- use a signal character.
Windows cmd.exe uses the aforementioned ampersand(s).
Unix shells tend to use the semicolon (;).
If you are asking about how to actually pass command-line arguments to your program, then try this little program out to get you started:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iomanip>
#include <iostream>
usingnamespace std;
int main( int argc, char** argv )
{
cout << "argument number: argument value\n";
for (int n = 0; n < argc; n++)
{
cout << setw( 2 ) << n << ": " << argv[ n ] << "\n";
}
return 0;
}
Hmm... I think I'll just try this stuff later on in my other program I'm writing. Checking for multiple inputs seams pretty difficult but I think that might as well be irrelevant anyways. I think I can sorta do this kind of stuff but command line programs aren't supposed to look all pretty anyways so I'll just ask for the inputs one at a time. So when I add a gui, checking for multiple inputs won't be necessary because I'll just have different input boxes and so fourth. I'll still try something like 12:00pm or something though to learn.
The solution seems like a very general string parsing algorithm, but I just wanted to see exactly what format you wanted to parse it in. We could then look at the analogous C++ code. Even pseudo-code would work.