you can't concatenate it?
float Pi = 3.14;
system("AdjustSeaLevel.exe " + Pi + " 5.4 11.2 c f g");
or make a variable that contains the string to pass in, and then issue that?
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
using namespace std;
int main(int argc, char **argv)
{
float Pi = 3.14;
std::string tosend;
std::ostringstream buff;
buff << Pi;
tosend = buff.str() + " 5.4 11.2 c f g";
cout << "something " + tosend;
return 0;
}
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
you can't put variables inside double quotes. That means it's a literal string then. You want the value of the variable, so you must take it out of the quotes..... You can't just take it out of quotes either, you must concatenate it.
system("AdjustSeaLevel.exe " + tosend);
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
#include <sstream>
int main(int argc, char** argv){
//...
//your code here
//...
stringstream toPass;
toPass << "AdjustSealevel.exe" << Pi;
system(toPass.cstr()); //it might me c_str() instead of cstr() not too sure
EXIT_SUCCESS;
}
Zcool31
Junior Poster in Training
55 posts since Mar 2009
Reputation Points: 10
Solved Threads: 3
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
>>Yeah, it's .c_str()
NO. it is .str() for string streams.It will return a string object on which you will have to do a .c_str(). So the corrected code would be somewhat like this:
#include<iostream>
#include<sstream>
int main()
{
std::stringstream arg;
const float pi=3.145745;
arg<<"AdjustSealevel.exe "<<pi;
std::cout<<arg.str().c_str();
system( arg.str().c_str() );
}
siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140
arg << "AdjustSealevel.exe c d e " << pi + DO_Reading +
OtherVarsEtc ;// is a error
int secondArgument=5;
std::string thirdArgument="somevalue";
arg<<"AdjustSealevel.exe "<<pi<<" "<<secondArgument<< " " << thirdArgument;
as you can infer, use << and not +
Its like this:
try to cout all the arguments and test as they will appear on screen.
cout<<"AdjustSealevel.exe "<<pi<<" "<<secondArgument<< " " << thirdArgument;
Now when you are confirmed that these are the EXACT argument you want to pass, just replace cout with arg.
siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140