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);
system("cls");
cout << "Type in a name:" << endl;
cin >> name;
system("cls");
cout << "Type in an age:" << endl;
cin >> age;
system("cls");
people << name << ' ' << age << endl;
people.close();
main();}
And here is search function:
void searchname(){
ifstream people("people.txt");
string name, nname;
int age;
system("CLS");
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;}}
system("pause");
people.close();
main();}
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...