The following code is meant to import data from a text file and store it in a vector, where the data is a x,y-Point. At the moment, it is not supposed to do anything else with the data. The code is based on a code snippet I found in this forum. The program compiles, but it doesn`t execute. What did I do wrong?
Line 18: The \ characters must be escaped. Not doing so results in an invalid file name and therefore your open is failing.
Line 18: You have no check that the open succeeds.
1 2 3 4 5
fin.open ("D:\\Sebisoft Erweiterung\\data.txt");
if (! fin.good())
{ cout << "unable to open input file" << endl;
exit (1);
}
Edit: Line 28: You don't check the the fin operation succeeded before you do the push_back. When you hit eof, you going to get an extra entry pushed on the vector.
Thank you, the problem really was the failing opening and me not checking on that.
While we are at it, another problem with the same programm arose with which you guys may also be able to help. I now wanted the program to print the points stored in points to the command window by means of some code I previously used somewhere else to output the contents of a vector. This time, the program doesn`t compile, stating that point is not a valid type for ostream. Do you have any suggestions as to solve or circumvent this problem?