对于以下输入:
8 23 24
67
95
程序A:
#include<iostream>
using namespace std;
int main()
{
while(fin>>k)
cout<< k<<endl;
return 0;
}
显示结果是:
8
23
24
67
95
using namespace std;
#include<fstream>
int main()
{
ifstream fin("vertor.in");
int k;
while(fin>>k)
cout<< k<<endl;
return 0;
}
~
程序C 每次读一整行:
#include<iostream>
using namespace std;
int main()
{
string s;
while(getline(cin,s))
cout<<s<<endl;
return 0;
}
其输入结果是:
8 23 24
67
95
#include<iostream>
using namespace std;
#include<fstream>
int main()
{
ifstream fin("vertor.in");
string s;
while(getline(fin,s))
cout<<s<<endl;
return 0;
}
~