您的位置:首页 > 其它

大文件的读写操作

2013-11-15 15:21 127 查看
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main() {
ifstream ifs("tuan.sql", ifstream::in);
ofstream ofs("trv.txt", ofstream::out);
string s,value;
char c1;
int start_pos=0,end_pos=0;
while(!ifs.eof() && !ifs.fail()) {
ifs >> s;
if(s[0] == '(') {
value += s;
continue;
}
int len = s.length();
for(int index=0; index<len;) {
if((index+1) <= len) {
c1 = s[index++];
if(c1==')'&&index!=len&&s[index]==',') {
end_pos = index;
value += " ";
value += s.substr(start_pos, end_pos);
value += "\n";
ofs << value;
value.clear();

start_pos = index + 1;
value += s.substr(start_pos,len);
start_pos=end_pos=0;
break;
}
if(c1==')'&&index==len) {
value += " ";
value += s;
value += "\n";
ofs << value;
value.clear();
start_pos=end_pos=0;
}
}else {
break;
}
}
}
ifs.close();
ofs.close();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: