Hello all,
I am having an issue with ifstream.
Short explanation:
1. I ask the user for the filename and read it via cin
2. I store the input in a c++ string
3. I use the input as the filename
Here's where it fails:
When a user enters something like input4.txt. When only alpha characters with one period is used the program works fine i.e. input.txt, myinput.txt, etc work fine. But when a user enters something like input4.txt, input10.txt, etc I get one of the following 2 errors:
in xcode: pointer being freed was not allocated
in gcc on linux: I just get incorrect output
Here's a snippet of my code:
cout << "Please enter the input file's name $";
cin >> inputFile;
ifstream infile;
infile.open (inputFile.c_str());
if (!infile.is_open()) {
cout << "Error, could not open input file\n";
exit(1);
}
If you need more information please feel free to let me know. Otherwise, does anyone know what I'm doing wrong and what I could do make this work?
Thanks!!