#include <iostream>
#include <fstream>
#include <string>
using namespace std;
main()
{
while(1)
{
ifstream file("run.inf");
string line;
string value0 = "protect = 0";
string value1 = "protect = 1";
do
{
getline(file, line);
} while(!file.eof());
// strange behavior of the program
if(line.find(value1))
{
cout << "protecting" << endl;
return 0;
}
else if(line.find(value0))
{
cout << "no protection" << endl;
return 0;
}
}
return 0;
}
how can I fix this error, when there is file conatining "protect = 1" program prints "no protecting" and vice versa?
How can I check if file exists?

New Topic/Question
Reply




MultiQuote





|