
-
将txt文件中的内容读取到整数变量中,txt文件内容:
-
1
2
3760569222770 760569402420 179650 431 1
3972158235210 3972158718970 483760 431 1
5160568876430 5160568982420 105990 431 1 -
使用istringstream类将读取的内容存储到整型变量并输出:
-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19int (){
ifstream infile("infdata.txt");
if(!infile) { cout<<" Data error !"<<endl; return 0;}
string s;
long a, b, c;
int d,e;
string Str1, Str2;
string Input;
while(getline(infile,Input))
{
cout<<Input<<endl;
istringstream iss(Input);
while(iss>>a>>b>>c>>d>>e){
cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;
}
}
return 1;
} -
在root命令行下运行输出各个整数值




近期评论