void load_custom()
{
string path = "customOpenCVsettings.txt";
ifstream fin;
fin.open(path); // Open the file
if (fin.is_open()) // If it opened successfully
{
fin>> var1 >> var2 >> var3>> var4;
std::cout << "open custom file a success" << std::endl;
fin.close(); // Close the file
}
If I "line them up", like ex.1 its not a problem. If I do it like ex.2, line after line, an error is thrown and window is closed usually is I list more than 3 going down.
What's really going on here and how do I load them like the second example, if possible.
ex. 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void load_custom()
{
string path = "customOpenCVsettings.txt";
ifstream fin;
fin.open(path); // Open the file
if (fin.is_open()) // If it opened successfully
{
fin>> var1;
fin>> var2;
fin>> var3;
fin>> var4;
std::cout << "open custom file a success" << std::endl;
fin.close(); // Close the file
}
Your output in line 10 (second example: 13) should probably go before line 9. Your message states that you opened the file successfully, and you know that immediately in line 8.
The reads may or may not have succeeded. You can check fin.good() after every read to see if the stream is still in a good state (the read was successful). So, you could print that the read was / was not successful at the locations you show if you want to.
Note: where you have the "open success" prints is technically correct. If you got there, the file did open correctly. But the stream state could already be corrupted.
good call
I've got a corrupted stream (it appears that way). Its been playing havoc with the programming trying to isolate whats wrong. As stated earlier it will function fine in the first several reads but resort to unusual behavior later, inserting values where there are ones, zeros where there should be >0.
Post the smallest possible complete program that illustrates the problem, don't forget to post a small sample of your input file as well. At very minimum we need to see how all the variables are defined and the sample input file.
One way to see a possible cause of this type of problem is read all the data as a string, printing each string on it's own line.
Remember if you have some piece of data that can not be held in the type of variable you're using the stream will error and no more input can be read until the error is cleared.
So what is the type of the params.filterByArea variable and what are you trying to cram into this variable?
Implementing your advice to error check the input settings file(.txt) I came across a deliberate space at position #7 for params.blobColor. I didn't know what else to put in the file at the time. I changed position 7 to a zero and like unlocking a key all of the bools went to 1, flagged vars put out the right value!
fin >> params.blobColor; //was set to "" changed to 0