-
Trouble with strstream
I'm trying to get strstream to work and its not working right. Both these code output stuff to a string except that it doesn't put a null so the output just keeps going until a zero. I'm using unmanaged VC.NET.
Code:
char buffer[1024];
ostrstream s(buffer, sizeof(buffer);
s << "hey" << uppercase << hex << 255 << endl;
// will work with this here, but it should even without:
// str[s.pcount()]=0;
cout << s.str();
Code:
strstream s;
s << "hey" << uppercase << hex << 255 << endl;
cout << s.str();
Output of both codes (nothing else is printed):
Code:
heyFF
══════════════════════════²²²²½½½½½½½½ε■ε■
-
Nevermind, I found the solution. To end a string stream, you must place a ends at the end (end string). That way the string will be terminated by a zero. So this works:
Code:
ostrstream s;
s << "hey" << uppercase << hex << 255 << ends;
cout << s.str();
<posting because someone might wanna search this topic later>