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#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.break ;
 
Topic archived. No new replies allowed.