code blocks 8.02 console program not outputting cout statements with SDL
im currently using the SDL-devel-1.2.13-mingw32 library in co开发者_StackOverflow中文版de blocks 8.02. with the mingw 5.1.6 installed separately on C:\ this program compiles and runs with no errors but i can't see the last system("pause"); on the screen. When i press any key, it of course skips over the system("pause"); then code blocks tells me that it successful ran. It also doesn'w show the cout << " SDL \n"; WTF?
#include <iostream>
#include <SDL.h>
using namespace std;
int main(int argc, char *argv[])
{
cout << " SDL \n";
cout << endl;
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) == -1) {
cerr << "Failed to initialize SDL: " << SDL_GetError() << endl;
exit(1);
}
atexit(SDL_Quit);
system("pause");`
return 0;
}
Depending on the options used to compile SDL, console output may be redirected to files called stdout.txt and stderr.txt -- this is the default for most Windows builds.
See this wiki article for a solution: http://www.libsdl.org/cgi/docwiki.cgi/FAQ_Console
This is really old, however there are two lines you can add to the beginning of your main() to get cout working:
freopen("CON", "w", stdout);
freopen("CON", "w", stderr);
精彩评论