0

I have had an issue with getline(cin,string) in several of my programs. The program does not allow the user to input information after the cout statement preceding getline(cin,string). Below is an example code of the issue I am having(Btw I am using code::blocks with GNU compiler):

#include <iostream>
#include <cstring>
#include <cstdlib>

using namespace std;

int main()
{
    int option;
    string name;
    cout<< "1. Yes"<<endl<< "2. No"<<endl;
    cout<< "would you like to see if there is an issue with this code: ";
    cin>>option;
    
    while(option == 1)
    {
        cout<< "Please enter your name: "<<endl;
        getline(cin,name);
        cout<<"Your name is: " << name<< endl;
        name.clear();
        cout<< "1. Yes"<< endl<< "2. No"<<endl;
        cout<< "Would you like to enter another name? "<<endl;

        cin>>option;

    }
    return 0;

}
1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by miguelsan
0

Sorry Please ignore this post, this seems to be a common problem and I found quite a bit of information on it. I figured out the issue. An admin can remove this post if needed.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.