i need the filename to say like salelog-(SALENUMBER VAR).pos. Everything i seem to do is failing. I have a book ordered but it wont be here untill next week
#include <iostream>
#include <string>
#include <sstream>
usingnamespace std;
int main() {
int myNumber = 10;
// Convert number to a string
ostringstream myNumberString;
if (!(myNumberString << myNumber)) {
cout << "myNumberString isn't valid number: " << myNumber << endl;
return 0;
}
// join them
string fileName = "salelog-" + myNumberString.str() + ".pos";
cout << fileName << endl;
return 0;
}
If you ever try to choice multiple char[] variables together into a string this will fail. You need to do something like string x = "blah" + string("blah2") + "blah3" + string("blah4"); // etc . This is because there is no operator for joining 2x char[] together. But string has an operator to add a char[] to it.
In this case ostringstream.str() returns a string, so there is no problem :)