I'm having issues with some code that I'm doing for an assignment. When I go and compile the file it sometimes works and sometimes it doesn't. The basic idea of the program is to read each line of text from a file and store it into an array (size of the array should be 100 and there should be 100 lines of text). Each string of text (each line) should be stored in it's own array address. Once all lines are stored the program is to pull each line from the array noting which line number it's from. When compiling it with Code::Blocks it runs with no problems, however, when I compile it with cygwin I go to run it and get an error message that says "terminate called after throwing an instance of 'std::bad_cast' what(): std::bad_cast Aborted (core dumped)"
Any help that you guys could give me would be greatly appreciated!
Here is the code that I've gotten so far:
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
string aFile[100];
ifstream nFile("TMA1Question4 Text.txt");
string nText;
if (nFile)
{
for (int nLineCounter=1; nLineCounter <=100; getline(nFile, nText))
{
aFile [nLineCounter] = nText;
nLineCounter++;
}
}
for (int nLineReader=1; nLineReader<=100; nLineReader++)
{
cout << "Line" << nLineReader << ": " << aFile[nLineReader] << endl;
}
return 0;
}