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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get StartedRecommended Textbook for
Entrepreneurship
Authors: Andrew Zacharakis, William D Bygrave
5th Edition
1119563097, 9781119563099
Students also viewed these Databases questions
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
View Answer in SolutionInn App