• 大文件的读写操作


     1 #include <iostream>
     2 #include <string>
     3 #include <fstream>
     4 using namespace std;
     5 
     6 int main() {
     7   ifstream ifs("tuan.sql", ifstream::in);
     8   ofstream ofs("trv.txt", ofstream::out);
     9   string s,value;
    10   char c1;
    11   int start_pos=0,end_pos=0;
    12   while(!ifs.eof() && !ifs.fail()) {
    13     ifs >> s;
    14     if(s[0] == '(') {
    15       value += s;
    16       continue;
    17     }
    18     int len = s.length();    
    19     for(int index=0; index<len;) {
    20       if((index+1) <= len) {   
    21         c1 = s[index++];
    22         if(c1==')'&&index!=len&&s[index]==',') {
    23             end_pos = index;
    24             value += " ";
    25             value += s.substr(start_pos, end_pos);
    26             value += "
    ";
    27             ofs << value;
    28             value.clear();
    29 
    30             start_pos = index + 1;
    31             value += s.substr(start_pos,len);
    32             start_pos=end_pos=0;
    33             break;
    34         }
    35         if(c1==')'&&index==len) {
    36           value += " ";
    37           value += s;
    38           value += "
    ";
    39           ofs << value;
    40           value.clear();
    41           start_pos=end_pos=0;
    42         }
    43       }else {
    44         break;
    45       }
    46     } 
    47   }
    49   ifs.close();
    50   ofs.close();
    51   return 0;
    52 }
  • 相关阅读:
    SQL整理5
    SQL整理1 数据类型
    SQL整理2
    JavaScript 的DOM操作
    JavaScript 数据类型
    JavaScript
    CSS样式表
    sqlserver数据库 提纲
    Python基础第十二天:二分法算法
    Python基础第十一天:递归函数
  • 原文地址:https://www.cnblogs.com/xuxu8511/p/3425502.html
Copyright © 2020-2023  润新知