I am a newbie here!Although this code completed outputting most of the file, it aborted just before it ended, what went wrong? (2VI3 is a huge data file for coordinates).
Could someone recommend better ways of writing this code?
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string *array = new string[2000];
ifstream iFile("2VI3_SA.txt");
if (!iFile.is_open()) {
cerr << "error: file cannot be opened" << endl;
abort();
}
int x = 0;
while (!iFile.eof()) {
getline(iFile, array[x]);
cout << array[x] << endl;
x++;
}
iFile.close();
cout << x << endl;
ofstream oFile("something.txt");
if (!oFile.is_open()) {
cerr << "error: file cannot be opened" << endl;
abort();
}
for (int i = 0; i < 2000; i++) {
if (i < 818) {
oFile << array[i] << "\n";
}
else if (i<1317){
oFile << array[i].substr(0, 8) << i - 378 << array[i].substr(11, 68) << '\n';
//renumbering all lines below the change
}
else {
oFile << array[i];
}
}
oFile.close();
delete[] array;
return 0;
}