+ 3
[SOLVED] While loop problem maybe?
In main() theres a while(true), and in the end theres break; also an if(!logout) then will not break the loop, the problem is when i run this code in OnlineGDB, it just display nothing and done with code 0, please help me đ https://sololearn.com/compiler-playground/cdy8kC8MCSls/?ref=app
5 Answers
+ 3
the way you read files seems so weird to me. I'm not on a PC to test it myself but i believe that's the problem. When working with files you must always check if you reach the end of the file by calling eof(). Here is my code
```
ifstream inFile("IsAdmin.txt");
/*consider check for errors here
if (!inFine.is_open()) {handle the error}*/
string adminkah = "";
while(!inFile.eof())
{
getline(inFile, adminkah);
if (usernamePrive==adminkah)
{
inFile.close();
return 1;
}
}
inFile.close();
```
+ 2
Sorry, I'm not really across c++, but maybe changing your login variable to a boolean True/False instead of a 0 could help. If the 0 and 1 already are that, maybe you need to check your break conditions in another way.
+ 1
you guessed right, its the infinite loop. Why not use a multithread?
+ 1
john ds after several days finnaly, thank you bro
0
Alright, thanks man for answering my question