Doing my best to understand what you mean . . .
In other words, you are creating a list of names, let's say, "names.txt", that contains something much like:
Code:
Allen
Brian
Crystal
David
Ellen
If someone enters the name "Brian", then your program will print "The name 'Brian' is in the list of names." -- whereas, if they enter "Varun", then the program will print "The name 'Varun' is not in the list of names."?
If so, then you will need to use
ifstream. One example of a program that reads in words, then prints them out to the screen on their own lines could be:
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
int main(int argc, char *argv[]) {
if(argc != 2) {
std::cout << "usage: " << argv[0] << " filename" << std::endl;
exit(1); /* NOTE: I'm not sure, in C++, if exit() is actually std::exit() or not. Probably. */
}
std::ifstream file(argv[1]);
if(!file.is_open()) exit(1);
bool done = false;
do {
std::string word;
file >> word;
std::cout << word << std::endl;
if(file.eof()) done = true;
} while(!done);
file.close();
return 0;
}
In C++, it is possible to compare strings against each other (
string1 == string2), since
operator==(const std::string &) is implemented by default.
That should be enough to get you started, at least.