【发布时间】:2016-05-14 02:49:55
【问题描述】:
我正在使用 fstream 和 C++,我想要我的程序做的就是将我的 .txt 文件的内容打印到终端。这可能很简单,但是我在网上查看了很多东西,但找不到任何可以帮助我的东西。我怎样才能做到这一点?这是我到目前为止的代码:
#include <iostream>
#include <fstream>
using namespace std;
int main() {
string output;
ifstream myfile;
ofstream myfile2;
string STRING;
myfile.open ("/Volumes/LFARLEIGH/Lucas.txt");
myfile2 << "Lucas, It Worked";
myfile >> STRING;
cout << STRING << endl;
myfile.close();
return 0;
}
提前谢谢你。如果这很简单,请原谅我,因为我对 C++ 很陌生
【问题讨论】:
-
您是否遇到错误
-
cout 后面多了一个 '}'
-
你打开同一个文件两次?
-
对这些事情感到抱歉 - 不相关。我没有收到错误,文件中的文本没有出现