I
hab ein ähnliches problem. hab mir den code von hier geklaut, der funktionierte auch immer -- bis gestern. aus heiterem himmel bekomm ich keine ausgabe mehr -- jedenfalls nicht per std::cout.
besonders interessant dabei ist, dass das hier
int conHandle;
long stdHandle;
FILE *fp;
// redirect unbuffered STDOUT to the console
stdHandle = (long)GetStdHandle( STD_OUTPUT_HANDLE );
conHandle = _open_osfhandle( stdHandle, _O_TEXT );
fp = _fdopen( conHandle, "w" );
*stdout = *fp;
setvbuf( stdout, NULL, _IONBF, 0 );
// make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog point to console as well
std::ios::sync_with_stdio();
std::cout << "hallo" << std::endl;
nicht funktioniert, das hier
int conHandle;
long stdHandle;
FILE *fp;
// redirect unbuffered STDERR to the console
stdHandle = (long)GetStdHandle( STD_ERROR_HANDLE );
conHandle = _open_osfhandle( stdHandle, _O_TEXT );
fp = _fdopen( conHandle, "w" );
*stderr = *fp;
setvbuf( stderr, NULL, _IONBF, 0 );
// make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog point to console as well
std::ios::sync_with_stdio();
std::cerr << "hallo" << std::endl;
aber schon. also cerr geht, cout nicht. und zwar seit gestern nachmittag.
ebenfalls interessant ist, dieses verhalten hier:
std::cout << "bla" << std::endl; //geht nicht
fprintf( stdout, "bla" ); //geht
hat jemand einen alternativen vorschlag, wie man cout/cerr auf eine neu erstellte console umleiten könnte?
<edit>
hab grad raus gefunden, dass es funktioniert, wenn ich vorhergehende cout's wegnehme. hatte in 'nem konstruktor ein cout drin, die umleitung wurde erst danach durchgeführt. ab dann ging gar nichts mehr über cout raus -- hat dafür jemand 'ne erklärung?
</edit>