Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何从控制台复制所有内容';输出到文本文件?_C++_Console - Fatal编程技术网

C++ 如何从控制台复制所有内容';输出到文本文件?

C++ 如何从控制台复制所有内容';输出到文本文件?,c++,console,C++,Console,我曾尝试过使用Sink和SaveHistory来实现这一点,但都没有成功。我也试过一些方法,比如从一个答案中找到这个问题的代码。我在VisualStudio2019中用空的解决方案制作了所有内容 没有任何错误,但当我这样做时: ofstream myfile; myfile.open("Addresses.txt"); myfile << printf << endl; myfile.close(); return 0; 流myf

我曾尝试过使用Sink和SaveHistory来实现这一点,但都没有成功。我也试过一些方法,比如从一个答案中找到这个问题的代码。我在VisualStudio2019中用空的解决方案制作了所有内容

没有任何错误,但当我这样做时:

    ofstream myfile;
    myfile.open("Addresses.txt");
    myfile << printf << endl;
    myfile.close();
    return 0;
流myfile的
;
myfile.open(“Addresses.txt”);

MyFrase

当你调用<代码> MyFrase:不相关的:<代码> MyFrime可能更简单,让C++在后面使用,并在命令行中使用重定向:<代码> MyStudio> MyField.txt< /Cord>

//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
}
int x;
std::cin >> x;
std::cout << "You Entered: " << x << std::endl;