Hi there,
i'm trying to use a ostringstream to insert two integers in a string.
This is my code at the moment:
1 2 3 4 5 6 7 8 9
|
bool SimuClient::bInitialisiereGrafik(int sizeX, int sizeY, bool bStarteServer) {
ostringstream ssNachricht;
// Init-Befehl senden
ssNachricht << "init " << sizeX << " " << sizeY << "#";
cout << ssNachricht.str() << endl;
cout << "size() = " << ssNachricht.str().size() << endl;
return false;
}
|
The output of this function is:
Does anyone know why the first integer isn't appended to the ostringstream?
My debugger says that "init " is followed by a \0. Why?!
Kind regards,
bob
Last edited on
This works for me. Try check your compiler settings. It is also possible that you have a strange sstream library.
I use gcc version 4.2.1 (Apple Inc. build 5646) on MacOS 10.6.1.
In my desperation I wrote another test program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <iostream>
#include <sstream>
using namespace std;
int main() {
ostringstream ss;
cout << "Ausgabe:" << endl;
ss << "init " << 5 << " " << 6 << "#";
cout << ss.str() << endl;
cout << "size() = " << ss.str().size() << endl;
return EXIT_SUCCESS;
}
|
and this works!
... confusing?!
Last edited on
Try flushing the stringstream
The problem is that I use Xcode as IDE.
When compiling in bash with g++ the program works fine.
Maybe some options in the Xcode build preferences are wrong.
Anyway, thanks for your helpful suggestions! :-)
Last edited on
The problem was that I compiled in Xcode for x64.
Switching to i386 solves the problem.