您的位置:首页 > 其它

在窗口应用中使用printf,cout 等将输出重定向到console

2007-01-25 12:25 477 查看

AllocConsole();




HANDLE hin = ::GetStdHandle(STD_INPUT_HANDLE);


HANDLE hout = ::GetStdHandle(STD_OUTPUT_HANDLE);




int hcin = _open_osfhandle((intptr_t)hin,_O_TEXT);


FILE* fpin = _fdopen(hcin,"r");


*stdin = *fpin;




int hcout = _open_osfhandle((intptr_t)hout,_O_TEXT);


FILE* fpout = _fdopen(hcout,"wt");


*stdout = *fpout;




std::ios_base::sync_with_stdio();




std::cout << "test";




int i;


std::cin >> i;




std::cout << i;

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: