Guest User

Untitled

a guest
Feb 18th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. ifstream inFile;
  10. inFile.open("userData.txt");
  11.  
  12. // Check for error
  13. if (inFile.fail()) {
  14. cerr << "error opening file" << endl;
  15. exit(1);
  16. }
  17.  
  18. string user, pass;
  19. int Count = 0;
  20.  
  21. // Read file till you reach the end and check for matchs
  22. while (!inFile.eof()) {
  23. inFile >> user >> pass;
  24. if (user == "Banana", "Apple") {
  25. Count++;
  26. }
  27. cout << Count << " users found!" << endl;
  28. }
  29. }
  30.  
  31. while (!inFile.eof()) {
  32. inFile >> user >> pass;
  33. if (user == "Banana", "Apple") {
  34. Count++; //no point in doing so because this only happens once
  35. }
  36. cout << Count << " users found!" << endl;
  37. }
  38.  
  39. while (!inFile.eof()) {
  40. inFile >> user >> pass;
  41. if (user == "Banana", "Apple") {
  42. Count++; //no point in doing so because this only happens once
  43. }
  44. cout << Count << " users found!" << endl;
  45. }
  46.  
  47. #include <iostream>
  48. #include <fstream>
  49. #include <string>
  50.  
  51. using namespace std;
  52.  
  53. int main()
  54. {
  55. ifstream inFile;
  56. inFile.open("userData.txt");
  57.  
  58. //Check For error
  59. if (inFile.fail()) {
  60. cerr << "error opening file" << endl;
  61. exit(1);
  62. }
  63.  
  64. string user, pass;
  65. int Count = 0;
  66.  
  67. //read file till you reach the end and check for matchs
  68. while (inFile >> user >> pass) {
  69. if (user == "Banana" && pass == "Apple") {
  70. cout <<"user found!" << endl;
  71. }
  72. }
  73. }
Add Comment
Please, Sign In to add comment