我有一个 ifstream 的问题。我想将 ifstream 分成 n 部分。
例如 n = 3:
- Ifstream 包含文件的前 1/3。
- Ifstream 包含文件的第二个 1/3。
- Ifstream 包含文件的第三个 1/3。
std::ifstream in("test.txt");
std::vector<std::string> v1;
std::vector<std::string> v2;
std::vector<std::string> v3;
//first 1/3 of file
read(in, v1);
//second 1/3 of file
read(in, v2);
//third 1/3 of file
read(in, v3);
read(in, v){
std::string line {""};
while(getline(in, line)){
v.pushback(line);
}
}