输入文本如下:
12345 23455 65477 34634
23355 55456 56666 35667
23445 63456 24566 24645
24545 24545 24555 23455
23455 24355 24356 24356
代码如下:
/*
读取每行的第二个整形数值
*/
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main(){
int temp1,m;
string s;
char buffer[30];
ifstream fin;
fin.open("number.txt",ios::in);
if(!fin.is_open()){
cout<<"Error opening file";exit(1);
}
//读取每行的第二个整形数值
/*//法一
while(!fin.eof()){
fin>>temp1>>m>>temp1>>temp1;
cout<<m<<endl;
}
*/
/*//法二
while(!fin.eof()){
fin.seekg(5,ios::cur);
fin>>m;
fin.getline(buffer,30);
cout<<m<<endl;
}*/
//法三
while(!fin.eof()){
getline(fin,s);
m=atoi(s.substr(6,5).c_str());
cout<<m<<endl;
}
return 0;
}
结果如下: