OK, so I've asked a question like this before and I thought I understood the answer (solved) but I am having problems again and I still do not understand why.
I am compiling with MinGW.
Here's the code:
string filename="D:/__GNU analyze/test/bin/Debug/_ClusterFormat/Test2.6d .txt";
fstream file, file2;
string cluster="frame";
string line;
Matrix AAA;
int position=0;
file.open(filename.c_str(), ios:: in);
if (file) cout << "YES\n"; else cout << "NO\n";
rulescheck6d(file);
position=ClusterPosition6d(file, cluster);
cout << "position: " << position << endl;
file.close();
filename="D:/_GNU analyze/test/bin/Debug/data/Test2.70cm.T01.A.6d.csv";
file2.open(filename.c_str(), ios:: in);
if (file2) cout << "YES\n"; else cout << "NO\n";
skipheader(file2);
MYgetline(file2,line);
AAA=read6dline(line, position);
AAA.dump(6,10);
file2.close();
I insert the if statements as debugging checks, which is why they are indented strangely (let's me find the lines to delete later).
When this code runs the first if statement returns YES, which means that "file" is open for reading. And, in fact, the functions that use this file operate properly and give the correct results.
The second if statement returns NO, which means that "file2" is not open for reading. This function that uses this file causes the program to crash.
WHY?
I originally wrote this code to reuse the variable name "file," but now I use "file" and "file2" without a difference in the outcome.
I am reusing the string "filename," but have tried this using "filename2" for the second instance without a difference in the outcome.
Yes, both files do indeed exist with the name and path as indicated. Neither file is empty.
You will see that I used exactly the same code to open both files -- file2.open(filename.c_str(), ios:: in);
But the first one opens and the second does not.
So, two questions:
Why is this happening?
How do I fix it?
Last time I asked a question like this I got more reponses to the "how do I fix it" question. Those responses worked for that particular application. But, since I still do not understand why this problem occurs, I am back again. So, please include an explanation of what is going on and what I am doing wrong. That way, I hope, I will not need to bother anyone again with this problem.
Thanks for your help.