c++ - Why does this work on Windows and break when I compile on Linux? -


i'm writing console application managing , tracking characters, monsters, turn order , conditions applied make battle run faster in dnd. following code works on windows when tried compile on laptop, runs linux, no longer works.

i input name, initiative, max health, when go add character reads blank string , sets name. i'm @ loss...

#include <iostream> #include <string> #include <vector> #include <algorithm>  void gvalid_input(std::string& var, std::string question = "add carriage return manually if want it...") {     using namespace std;      {         cin.clear();         cin.sync();         cout << question;     } while (!getline(cin, var)); }  template <typename t> void gvalid_input(t& var, std::string question = "add carriage return manually if want it...") {     using namespace std;      {         cin.clear();         cin.sync();         cout << question;     } while (!(cin >> var)); }  void gvalid_option(char& response, std::vector<char> valid_responses = {'y','n'}){     using namespace std;     const char diff = 'a' - 'a';      do{         cin.clear();         cin.sync();         cin >> response;          if (response >= 'a' && response <= 'z'){             response += diff;         }      } while (find(valid_responses.begin(), valid_responses.end(), response) == valid_responses.end()); }  void gvalid_option(char& response, std::string question, std::vector<char> valid_responses = {'y','n'}){     using namespace std;     const char diff = 'a' - 'a';      do{         cin.clear();         cin.sync();         cout << question;         cin >> response;          if (response >= 'a' && response <= 'z'){             response += diff;         }      } while (find(valid_responses.begin(), valid_responses.end(), response) == valid_responses.end()); } 

solved

void gvalid_input(std::string& var, std::string question = "add carriage return manually if want it...") {     using namespace std;      {         cin.clear();         cin.sync();         cout << question;         if (cin.peak() == '\n'){             cin.ignore(1, '\n');         }     } while (!getline(cin, var)); } 


Comments