我有数字文本数据行,大小在1mb-150mb之间,我需要写出与高度有关的数字行,例如:heights = 4,新文本必须包括行:1,5,9,13,17,21 ....因此。需要将文本的特定行写入新文本
我一直在试图找到一种方法来做到这一点,现在尝试使用列表而不是矢量结束了编译错误。
我已经清除了建议的代码。它现在写入所有行sample2文本,全部在这里完成。谢谢大家
只要它提供我需要的东西,我就会接受方法更改,感谢您的时间和帮助。
以下是我迄今为止:
#include <iostream>
#include <fstream>
#include <string>
#include <list>
#include <vector>
using namespace std;
int h,n,m;
int c=1;
int main() {
cout<< "Enter Number Of Heights: ";
cin>>h;
ifstream myfile_in ("C:\\sample.txt");
ofstream myfile_out ("C:\\sample2.txt");
string line;
std::string str;
vector <string> v;
if (myfile_in.is_open()) {
myfile_in >> noskipws;
int i=0;
int j=0;
while (std::getline(myfile_in, line)) {
v.push_back(line);
++n;
if (n-1==i) {
myfile_out<<v[i]<<endl;
i=i+h;
++j;
}
}
cout<<"Number of lines in text file: "<<n<<endl;
}
else cout << "Unable to open file(s) ";
cout<< "Reaching here, Writing one line"<<endl;
system("PAUSE");
return 0;
}
“恒定高度添加”?请改述你的问题。在目前状态 – Arunmu
和..yeah ..无法理解,欢迎来到:) – Arunmu
完成...谢谢:) – Mario