c++ 读文件的问问题
要求是必须一个一个字符或数据依次输出 不能直接输出整行
这是我的代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
char c;
ifstream fp("data.txt",ios::in);
while ((c = fp.get()) != EOF)//要求逐个输出,不可直接输出整行
{
cout << c;
}
}
下面是我data.txt里的内容
1 1 1 1 1 1 1
2 2 2 2 2 2 2
3 3 3 3 3 3 3
最后的输出结果是只输出了第一行1 1 1 1 1 1 1
剩下两行都没有输出
怎么才能让每行都输出出来呢
我的电脑上能全部出来:
1 1 1 1 1 1 1
2 2 2 2 2 2 2
3 3 3 3 3 3 3
--------------------------------
Process exited after 1.504 seconds with return value 0
请按任意键继续. . .
你把头文件换成以下一行,试试:
#include<iostream>