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;

}

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.