While loop problem maybe? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 2

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

28th Apr 2024, 1:13 PM
LemonKitana
LemonKitana - avatar
4 Antworten
+ 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.
28th Apr 2024, 2:43 PM
Ausgrindtube
Ausgrindtube - avatar
+ 1
you guessed right, its the infinite loop. Why not use a multithread?
28th Apr 2024, 8:09 PM
White Shadow
White Shadow - avatar
+ 1
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(); ```
18th May 2024, 11:17 PM
john ds
john ds - avatar
0
Alright, thanks man for answering my question
29th Apr 2024, 2:28 PM
LemonKitana
LemonKitana - avatar