【发布时间】:2017-09-08 22:22:26
【问题描述】:
我正在尝试制作一个使用命令行来显示数据的脚本,并且我希望能够将输出到命令行的所有内容记录到一个单独的文件中。
我正在使用 fstream、iostream 和 std 命名空间。我只需要知道如何引用命令行 CmdExample.exe 以及它所说的将其写入 txt 文件的所有内容。
例子:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
cout << "This is some text I want to reference when the program ends" << endl << "and write to a txt file.";
return 0;
}
【问题讨论】:
-
通常你会做
CmdExample.exe > output.txt。 -
也许你正在寻找类似stackoverflow.com/questions/24413744/…的东西。