前言
在使用boost库函数时有些返回值不能直接用QDebug输出,就索性使用std::cout,所以这里简单记录下将cout信息输出在QtCreator应用输出栏里面的小过程。
单独使用std::cout,会在程序退出的时候打印在输出栏。
我就截取一段我正在用的代码了,不单独写了,关注std::cout就行了。
bimap mybimap;
mybimap.insert(bimap::value_type(1,"a"));
mybimap.insert(bimap::value_type(2,"b"));
auto itor_left = mybimap.left.find(2);
if(itor_left != mybimap.left.end())
{
std::cout<<"left value="<<itor_left->second<<std::endl;
}
auto itor_right = mybimap.right.find("a");
if(itor_right != mybimap.right.end())
{
std::cout<<"right value="<<itor_right->second<<std::endl;
}
我一开始用的时候发现没有打印信息,关闭程序时竟然打印出来了,八成和cout缓存有关系,随之在cout打印后面直接加了一行代码std::cout.flush();就正常打印了。
std::cout<<"left value="<<itor_left->second<<std::endl;
std::cout.flush();
后面把cout.flush()删除重新编译也能正常打印了,不知道重启电脑后没这行代码还能不能正常打印,由于时间原因这里就不尝试重启电脑测试了。有兴趣的小伙伴可以试试。