-3

I have this code where the string info is not working as it should.

I have a getline where info is inside and it saves a hole sentence, but it won't output more than the first word.

Example:

"Hello world!"

I will only show me "hello"

Here is the part of the code:

 void add() {
 string name;
 string faction;
 string classe;
 string race;
 string info;
 ofstream wowdatabase("wowdatabase.txt", ios::app);
 cout << "Add a race or class" << endl;
 cout << "---------------------------------------------------------" << endl;
 cout << "" << endl;
 cout << "Enter the name of the race or class (only small letters!):" << endl;
 cin >> name;

 cout << "Enter Race (Type -, if writen in name section):" << endl;
 cin >> race;

 cout << "Enter Class (Type -, if writen in name section):" << endl;
 cin >> classe;


 cout << "Enter faction (Alliance/Horde):" << endl;
 cin >> faction;
 cin.ignore( numeric_limits<streamsize>::max(), '\n' );

 cout << "Enter the information:" << endl;
 getline(cin, info);

 cout << info;
 system("pause");
 wowdatabase << name << ' ' << faction << ' ' << classe << ' ' << race << ' ' << info      << endl;
 wowdatabase.close();
 system("CLS");
 main();
 }
 void searchname() {


 ifstream charecter("wowdatabase.txt");
 string name;
 string find;
 string faction;
 string classe;
 string race;
 string info;
 int i = 0;


 system("CLS");
 cout << "Search for a race or class" << endl;
 cout << "---------------------------------------------------------" << endl;
 cout << "" << endl;
 cout << "Please enter name:";
 cin >> find;

 while (charecter >> name >> faction >> classe >> race >> info ) {
       if (find == name) {
               system("CLS");
               cout << "Charecter found" << endl;
               cout << "---------------------------------------------------------" << endl;
               cout << "" << endl;
               cout << "Name of race/class: " << name << endl;
               cout << "Race: " << race << endl;
               cout << "Class: " << classe << endl;
               cout << "Faction: " << faction << endl;
               cout << "Info: " << info << endl;
               cout << "" << endl;
               cout << "Press enter to return to menu" << endl;
               system("pause");
               system("CLS");
               main();
       }
}
abelenky
  • 63,815
  • 23
  • 109
  • 159

1 Answers1

0

You use variable info in several functions. For example in function searchname() you enter it as

while (charecter >> name >> faction >> classe >> race >> info )

that is in this function you do not use getline. Also your code is invalid because you may not recursively call main in C++.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335