In C++, I developed a simple application that requested the user to enter a number and then a string.
Surprisingly, when I ran the application, it never paused to ask for the string.
It simply ignored it.
After conducting some research on StackOverflow, I discovered that I needed to include the following line:
cin.ignore(256, '\n');
before the line with the string input
That addressed the problem and allowed the software to run.
My issue is why C++ need the cin.ignore() line, and how can I forecast when I will need to use it.
Here's the software I created:
#include <iostream>
#include <string>
using namespace std;
int main()
{
...READ MORE
Jul 4, 2022
in C++
by
Nicholas
• 7,760 points
•
760 views