passing variables to system

I am wondering how I can pass a variable to the system function. i.e.:

int x=3;
char y='B';
system("color" x y);

Obviously the code doesn't work like that, but you get the point.
system function's signature is int system(const char* command);. So in short, it does not take second argument.
how about:
string a;
system(a.c_str());
In this case, why not just use SetConsoleTextAttribute() ?
http://www.google.com/search?btnI=1&q=msdn+SetConsoleTextAttribute
If its possible to make x and y strings...

 
system(("color "+x+y).c_str());
Last edited on
You can use sprintf ( C style ) http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/
Or stringstreams:
1
2
3
stringstream ss;
ss << "color " << x << y;
system( ss.str().c_str() );
BTW, don't use 'system' http://www.cplusplus.com/forum/articles/11153/
Topic archived. No new replies allowed.