【发布时间】:2019-09-26 03:14:07
【问题描述】:
我已经尝试过 Sink 和 SaveHistory 来执行此操作,但都没有成功。我还尝试了诸如来自答案之一的这个问题的代码之类的东西。 How to output to the console in C++/Windows。我在 Visual Studio 2019 的空解决方案中制作了所有内容。
没有任何错误,但是当我这样做时:
ofstream myfile;
myfile.open("Addresses.txt");
myfile << printf << endl;
myfile.close();
return 0;
它打印出随机数。
//Code I tried
#include <iostream>
using namespace std;
int main (int) {
cout << "This will print to the console!" << endl; // I don't know how to make it read all of the output
}
我的目标是将控制台的整个输出放入我选择的文本文件中。 (地址.txt)
【问题讨论】:
-
不相关:
myfile << printf << endl;很可能会导致人们因重复使用printf而抓狂。除非你真的想打印printf函数。在那种情况下,为什么? -
将 C++ 抛在后面并在命令行中使用重定向可能会更简单:
MyProgram > myfile.txt