C ++ ofstream与C ++ cout通过管道传输到文件 [英] C++ ofstream vs. C++ cout piped to file

查看:137
本文介绍了C ++ ofstream与C ++ cout通过管道传输到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一组单元测试,这些单元测试会将计算出的值写到文件中.每个测试产生一个正方形矩阵,该正方形矩阵可容纳50,000至500,000个双精度点,我总共有128个测试用例组合.

I'm writing a set of unit tests that write calculated values out to files. Each test produces a square matrix that holds anywhere from 50,000 to 500,000 doubles, and I have a total of 128 combinations of test cases.

编写cout语句,然后将其管道传输到文件中是否有任何重大开销,还是最好使用ofstream直接写入文件中?

Is there any significant overhead involved in writing cout statements and then piping that output to files, or would I be better off writing directly to the file using an ofstream?

推荐答案

这将取决于您的系统和环境.这种差异可能很小,但是只有一种方法可以确保:尝试两种方法并对其进行度量.

This is going to be dependent on your system and environment. This likely to be very little difference, but there is only one way to be sure: try both approaches and measure them.

这篇关于C ++ ofstream与C ++ cout通过管道传输到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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