Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <string>
- #include <thread>
- int main()
- {
- // Loop for ever, so user can enter pins to search for them in a file
- while(true)
- {
- // User Input
- std::cout << ("Please enter your PIN: ");
- std::string pin;
- std::cin >> pin;
- // Validate user input
- // if this fails, the loop will continue to the start!!! *IMPORTANT*
- if(pin.length() != 4) {
- std::cout << "\033[2J\033[1;1H";
- std::cout << "Your pin is to long/short/incorrect. Please try again\n";
- std::this_thread::sleep_for(std::chrono::seconds(3));
- continue;
- }
- // If we got here, the above verifcation was successful!! *IMPORANT*
- // Open the file to begin a search for the pin entered above **IMPORATNT**
- std::ifstream file_in("file.txt");
- // Search file for pin **STARTING AT BEGINNING**
- while (file_in)
- {
- // Read next line from file
- std::string line;
- std::getline(file_in, line);
- // Check if the above getline failed if we have read the entire file
- // When we have completed reading the whole file, the eof() END_OF_FILE
- // flag is set. So we cant read any more data. EXIT THE LOOP - BREAK.
- if(file_in.eof()) { break; }
- // if we got here, the above getline DIDNT fail. so there is data in the
- // line string. Print it.
- // Print the line
- std::cout << line << "\n";
- }
- // Close file after search is concluded!!!! **IMPORATNT**
- file_in.close();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement