【发布时间】:2014-11-01 06:57:45
【问题描述】:
我想将填充中的所有文本显示到输出, 我使用下面的代码,我起床的代码和结果帖子只是有点出来
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
char str[10];
//Creates an instance of ofstream, and opens example.txt
ofstream a_file ( "example.txt" );
// Outputs to example.txt through a_file
a_file<<"This text will now be inside of example.txt";
// Close the file stream explicitly
a_file.close();
//Opens for reading the file
ifstream b_file ( "example.txt" );
//Reads one string from the file
b_file>> str;
//Should output 'this'
cout<< str <<"\n";
cin.get(); // wait for a keypress
// b_file is closed implicitly here
}
上面的代码只是简单的显示“This”这几个字并没有全部输出到output.yang我想要的是文件中的所有文本都出现在控制台中..
【问题讨论】: