How to compare file data to local variable

Hi,

I recently learned about the ifstream and ofstream classes. Now, what I'd like to do is have a user input file to a text file, and the next time he or she would open the program it would ask them to enter that word again, kind of like a password but not really a password. I currently have it so that I edited the file myself and it says the word "Epicness" but I currently do not know exactly how to compare the user's input to the text in the file. The file is named "LastWord.dat". If anyone could please tell me how to save the info in the .dat file to a local variable to compare to a user's input I would appreciate that.

Thanks,

-Awesomeprograms

Last edited on
Now, what I'd like to do is have a user input file to a text file, and the next time he or she would open the program it would ask them to enter that word again


I am not 100% sure about what you mean there but checking if a word exists in a file is not difficult.

1
2
3
4
5
6
7
8
9
10
        ifstream fin;
        string tmp;

	fin.open("<filename here>");
	
	while (fin >> tmp)
	       if (tmp == "<word your looking for>")
	             cout << "Verified\n";   // do something here
	
Last edited on
Topic archived. No new replies allowed.