Comparing 2 strings from a I/O file.
Mar 10, 2008 at 12:24am UTC
OK...i want to be able to compare 2 strings from a .txt file. My program is like a account creation page. The user inputs his name and password in, it then saves to a .txt file, and then to 'sign' in i want to compare the two strings and print a success msg or failed msg.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ifstream inFile; //input file
ofstream outFile; //output file
string name;
string password;
char userSelect;
int Exit = 0;
const int SENTINEL = Exit;
cout <<"*******Final Project*******\n\n\n" << endl;
cout << "\n Please select from the three options.\n"
<< "B to Begin\n"
<< "C to Create\n"
<< "E to Exit"
<< endl;
cin >> userSelect;
switch (userSelect)
{
case 'C' : case 'c' :
inFile.open("pw.txt" );
outFile.open("pw.txt" );
outFile << "name: " ;
outFile << name;
cout << "Choose a Name you would like to use that is \n"
<< "no longer than 10 characters and is one word,"
<< " \nor type E to exit.\n" ;
cin >> name;
outFile << name;
outFile << " pw: " ;
outFile << password;
cout << "\nChoose your password. No more than 10 characters\n" ;
cin >> password;
outFile << password;
cout << " " <<endl;
inFile.close();
outFile.close();
break ;
case 'B' : case 'b' :
inFile.open("pw.txt" );
outFile.open("pw.txt" );
string str1 ("name: " );
string str2 ("pw: " );
cout << "Type in your user name.\n" ;
cin >> name;
cout << "\nType in your password.\n" ;
cin >> password;
case 'E' : case 'e' :
cin >> Exit;
default :
cout << " That is an invalid option." <<endl;
break ;
}
return 0;
}
Last edited on Mar 10, 2008 at 12:43am UTC
Mar 10, 2008 at 2:03am UTC
Well Good Luck.
Your question is....?
your code has improved but you are still missing a couple of break ;
oh and initialize string str1 and str2 outside of the switch loop, some good compilers will tell you that its a logical error.
Jeff
Topic archived. No new replies allowed.