C ++:cout语句会使代码变慢吗 [英] C++: Does cout statement makes code slower

查看:55
本文介绍了C ++:cout语句会使代码变慢吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从一个文件中读取大约300万行,并将其插入STL映射中.因此,在我从文件中读取每一行的while循环中,我还通过一个简单的cout语句打印以控制台其行号.我的一位朋友最近指出,这会使代码变慢.我想知道这是否是真的,是否是为什么?

I am reading about 3 million rows from a file and inserting them into STL maps. So, inside my while loop where I read each line from the file, I also print to console what row number it is through a simple cout statement. One of my friends recently pointed out that this makes code slower. I was wondering whether it is true and if it is why?

推荐答案

正如已经提到的,写入终端几乎肯定会比较慢.为什么?

As already mentioned, writing to the terminal is almost definitely going to be slower. Why?

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆