Question: This is a section of my code where I've narrowed down my problem is. The code keeps truncating the first letter of the inputs from
This is a section of my code where I've narrowed down my problem is. The code keeps truncating the first letter of the inputs from the user after the first response.
im assuming that my problem is with my getline statement or my ignore statement?
string generateMadLib(vector& madLibs, vector& labels) { for (int i = 0; i < madLibs.size(); i++) { string madLib = madLibs[i]; int pos = madLib.find("REPLACE"); while (pos != string::npos) { string label = labels[i]; string article = getArticle(label); cout << "Enter " << article << " " << label << ": "; string userInput; cin.ignore(); // Clear the newline character left in the buffer getline(cin, userInput); madLib = madLib.replace(pos, 7, userInput); pos = madLib.find("REPLACE"); i++; } return madLib; Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
