现在的位置: 首页 > 综合 > 正文

c++ 读写文件程序

2013年10月06日 ⁄ 综合 ⁄ 共 536字 ⁄ 字号 评论关闭

我的第一个入门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;
}

抱歉!评论已关闭.