#偷懒系列#大组数据切块

缘起

做 project2 的时候,产生了四百万条数据。但是一个excel表只能处理一百万多一点的数据,然而用人手把这四百万条数据分成四份几乎不可能,所以我写了一个小程序来干这事。

演示

这里写图片描述
四百万组数据放在TXT里,打开都卡……
这里写图片描述
处理前的目标目录,只有一个excel表格
这里写图片描述
我们跑一跑
这里写图片描述
发现生成了四个文件
这里写图片描述
和源文件的大小对比下,是不是拆成四个了?

源代码

//     When I do my project2, my program produce four 
// million data which is too much for a single excel chart.
// However, it is impossible to divide it into four by hand,  
// so I write this program to hele me.
//     做 project2 的时候,产生了四百万条数据。但是一个excel
// 表只能处理一百万多一点的数据,然而用人手把这四百万条数据
// 分成四份几乎不可能,所以我写了一个小程序来干这事。


#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main() {
    // the input file
    ifstream inFile("out2.txt");

    // divide the input file into four files
    ofstream file[4];
    file[0].open("out2/out1.txt");
    file[1].open("out2/out2.txt");
    file[2].open("out2/out3.txt");
    file[3].open("out2/out4.txt");
    string str;

    for (int i = 0; i < 4; i++) {
        int counter = 0; 
        while ((!inFile.eof()) && (counter <= 1048575)) {
            getline(inFile, str);
            counter++;
            file[i] << str << endl;
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值