我的第一个入门C++程序,感谢官山同学对我在C++方面的耐心引导,这将成为我在编程方面的一个里程碑式的开始!
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream readfile;
readfile.open("c:\\1.txt",ios::in);
string line;
int start=0;
string result;
ofstream writefile;
writefile.open("c:\\2.txt",ios::out|ios::app);
while (getline(readfile,line))
{
if (line.find("geliping")!= string::npos)
{
start = line.find("geliping");
result = line.substr(start,8);
writefile<<result<<endl;
}
else
continue;
//cout<<line<<endl;
//writefile<<line<<endl;
}
readfile.close();
writefile.close();
return 0;
}