Of course there is
int main(int argc, char* argv[])
{
string args;
for(int i = 1; i < argc; i++)
{
args += argv[i];
args += ' '; // add space between args
}
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
See my previous post -- I added a line to put a space between the arguments.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Well the error is on this line: printf(args); .printf is a function inherited from C, and therefore can't handle C++ strings, I would suggest you to use cout instead:
cout << args << endl; .
But you could of course also convert the C++ string to a constant C string, by using thec_str() method from the string class, in that case it would be possible to display the string using printf: printf("%s\n", args.c_str());
:)
tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
Hmmm, that'd be because I've used C before, I thought they were very similar ;)
Well, C != C++ remember that :)
tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
sprintf(cmd,"python mypyfile.py %s",args.c_str());
system(cmd);
You could do it this way to, to avoid using C character arrays.
string args = "python mypyfile.py ";
for(int i = 1; i < argc; i++)
{
args += ' '; // add space between args
args += argv[i];
}
system(args.c_str());
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343