how do I use local variables with the system() call

say I have a variable declared as
string str = "filename";
and I want to do
system( "wget www.someurl.com -O <value of str>" );
how would I go about doing it?
Use std::string::c_str()

Example:
1
2
3
4
5
6
std::string str;

std::cout << "$ ";
std::getline(std::cin, str);

system(str.c_str);


I'd like to add that you probably shouldn't use system(): http://cplusplus.com/forum/articles/11153/
Thanks for pointing out that using system() is bad practise, would fork/exec be a better alternative?
Infinitely, because exec allows you to specify command line arguments.
Just to be clear:
1
2
3
4
5
string filename = "filename";

string command = "wget www.someurl.com -0 ";
command += filename;
system( command.c_str() );
Yes, you can do that, but considering the article you wrote about the matter, I'd say it's still a lot better to use fork/exec...

:)
Topic archived. No new replies allowed.