C++整理大数据文件vector

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>




struct MyDate
{
string str1;
string str2;
// string str3;


};
int strGetDate()
{
ifstream fin("test.txt");
if (fin.bad())
{
cout<<"error when open file"<<endl;
return -1;
}
string str ="";
vector<MyDate>vctMyDate;
while (getline(fin,str))
{
if (str!="")
{
MyDate oneDate;
vector<string>vct;
string newStr="";
string strIend =",";
unsigned int iPod = str.find(strIend);
if (iPod!=string::npos)
{
while (iPod!=string::npos)
{
string strIear = str.substr(0,iPod);
string strRces = str.substr(iPod+strIend.size());
newStr += strIear+','+"0x";
str = strRces;
iPod = str.find(strIend);
}
str = str.substr(0,str.size()-1);
newStr +="\t\""+str+"\"";
string strIend2 = ",0x\t";
iPod = newStr.find(strIend2);
string strIear =newStr.substr(0,iPod);
string strRces = newStr.substr(iPod+strIend2.size());
newStr = strIear+"\t"+strRces;
vct.push_back(newStr);
oneDate.str1=vct[0];
}
else
{
str = str.substr(0,str.size()-1);
str ="\""+str+"\"";
str ="," +str;
vct.push_back(str);
oneDate.str1=vct[0];
}
vctMyDate.push_back(oneDate);
}
}
//把数据传入新的文件中
string strFileName = "newText.txt";
//ofstream fout(strFileName.c_str(),ios::app);
ofstream fout(strFileName.c_str());
//int iCtrl=1;
for (vector<MyDate>::iterator pPos = vctMyDate.begin();
pPos!=vctMyDate.end(); 
pPos++)
{
fout<<pPos->str1<<pPos->str2;
// if (iCtrl%3==0)
// {
// fout<<endl;
// }
// iCtrl++;
}
fout.close();
fin.close();
return 0;


}


void fnMakeTextFile(string strFileName,string str)
{
ofstream fout(strFileName.c_str(),ios::app);


fout<<str<<endl;
fout.close();
}
int main(void)
{
strGetDate();


return 0;
}
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页