J
jay
I was told that an ostringstream should be terminated by ends.
However, the following code snippet does not do what I would expect if
that were the case:
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
ostringstream oss;
string myString;
long aCounter = 0;
oss << ++aCounter << ends;
myString = oss.str() + "_SUFFIX";
cout << myString << endl; // output: "1 _SUFFIX", unexpected
oss.str("");
oss << ++aCounter;
myString = oss.str() + "_SUFFIX";
cout << myString << endl; // output: "2_SUFFIX", wanted
}
So, my question is basically: what is the purpose of ends ?
-j-
However, the following code snippet does not do what I would expect if
that were the case:
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
ostringstream oss;
string myString;
long aCounter = 0;
oss << ++aCounter << ends;
myString = oss.str() + "_SUFFIX";
cout << myString << endl; // output: "1 _SUFFIX", unexpected
oss.str("");
oss << ++aCounter;
myString = oss.str() + "_SUFFIX";
cout << myString << endl; // output: "2_SUFFIX", wanted
}
So, my question is basically: what is the purpose of ends ?
-j-