有a.txt文件(大概10来M),其中格式如下:
wyz 58.282926 0.000000 18.466503 23.750000
wyz 58.282926 0.000000 18.466503 23.750000
wyz 58.282926 0.000000 18.466503 23.750000
wyz 58.282926 0.000000 18.466503 23.750000
wyz 58.282926 0.000000 18.466503 23.750000
wyz 58.282926 0.000000 18.466503 23.750000
wyz 58.281897 0.000000 18.466503 23.750000
wyz 58.281897 0.000000 18.466503 23.750000
wyz 58.281897 0.000000 18.466503 23.750000
wyz 58.281897 0.000000 18.466503 23.750000
wyz 58.281897 0.000000 18.466503 23.750000
要求:提取每行的“58.xxxxxx” 以及 “18.xxxxxx”,并写入到b.txt文件,格式如下:
58.281897 18.466503
58.286437 18.445303
58.257667 18.476503
代码:
ifstream is("a.txt");
string textline;
getline(is,textline);
istringstream line(textline);
string number;
ofstream os("b.txt");
while(line >> number)
{
if(number.find("58.",0) != string::npos)
os<<number<<" ";
if(number.find("18.",0) != string::npos)
os<<number<<endl;
}
is.close();
os.close();