如何将控制台输出写入cpp中的文本文件? [英] How to write console output to a text file in cpp?

查看:149
本文介绍了如何将控制台输出写入cpp中的文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将控制台数据写入cpp中的单独的文本文件。任何人帮助我的示例代码。

I'm trying to write console data into a separate text file in cpp. Anybody help me with sample code.

推荐答案

有很多方法来做到这一点。您可以从命令行重定向 programname> out.txt 。或者你可以在程序开始时使用 freopen(out.txt,w,stdout);

There are various ways to do this. You could redirect it from the command line with programname > out.txt. Or you could use freopen("out.txt","w",stdout); at the start of your program.

这篇关于如何将控制台输出写入cpp中的文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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