#include <iostream>
using namespace std;
#include <fstream>//1.包含读文件
//文本文件 读文件
void test01()
{
//2.创建流对象
ifstream ifs;
//3.打开文件,并判断是否打开成功
ifs.open("test.txt", ios::in);
if (!ifs.is_open())
{
cout << "文件打开失败" << endl;
return;
}
//4.读数据
char buf[1024] = { 0 };
while (ifs >> buf)
{
cout << buf << endl;
}
//5.关闭文件
ifs.close();
}
int main()
{
test01();
return 0;
}
是正常的啊,你检查一下那个文件里有没有东西,我好像看到上一个问题中,你的那个文件写的地方有问题,你把它写成了
ofs.open("test.text", ios::out);