64,648
社区成员
发帖
与我相关
我的任务
分享
struct FileHead
{
char m_szFileName[256];
int m_nSize;
};
FileHead headFile;
strcpy(headFile.m_szFileName, "test.txt");
headFile.m_nSize = 1024;
read(&headFile, sizeof(FileHead));
write(&headFile, sizeof(FileHead));
#include<fstream>
#include<iostream>
#include<string>
using namespace std;
int main()
{
ifstream fin("AreaCode.txt");//输入的文件
ofstream fout("AreaCodeplus.txt");//输出的文件
string a;
while(getline(fin,a))//从文件中提取一行
{
int position1=a.find('|',0);//找到第一个分隔符的位置
int position2=position1;
for(int j=0;j<4;++j)//找到第五个分隔符的位置
{
position2=a.find('|',position2+1);
}
//cout<<position1<<" "<<position2<<endl;
//输出需要的部分:第一个分隔符之前,和第五个分隔符之后
fout<<a.substr(0,position1)<<a.substr(position2)<<endl;
}
cout<<"Done\n";
fin.close();
fout.close();
return 0;
}