Problem with comparing strings

Hello, i have a problem with comparing 2strings...
I made a database program using files. I have a problem when i want user to search for a persons name from that file... When i input name in search it either doesn't recognize it, or it prints out that person's name + message that name doesn't exist... anyway here is part of code:

void input(){
string name;
int age;
ofstream people("people.txt", ios::app);
cout << "Type in a name:" << endl;
cin >> name;
cout << "Type in an age:" << endl;
cin >> age;
people << name << ' ' << age << endl;

And here is search function:
void searchname(){
ifstream people("people.txt");
string name, nname;
int age;
cout << "Type a name you are looking for:";
cin >> nname;
while(people >> name >> age){
if (nname == name){
cout << "People found:" << endl;
cout << name << age << endl;}
if (nname != name){
system ("CLS") ;
cout << "There is no person with that name." << endl;}}
What is this statement doing in function input?

Last edited on
it's used to return to the main function, there is a switch case function from where you can choose if you want to add a new person, search database and so on...

Please, enter any book on C++ for beginners and investigate how functions are called and how do they return the control.
Topic archived. No new replies allowed.