getline

1
2
3
4
5
6
7
8
9
10
11
12
void Add(string artist[], string song[], int i, int j)
{
     string line;
     size_t found;
     
     cout << "Please enter the artist and song you would like to add:" << endl;
     getline(cin,line);
     found = line.find(':');    
     artist[i] = line.substr(0,found);
     song[j] = line.substr(found + 1);
     Show(artist, song, i, j);
}


I want to generate a substring from the user input using the getline function, but when I run the program it just skips the user input and nothing happens. I also tried:

cin.getline(line, 256);

but received an error when i tried that. Thoughts? Ideas? Thanks in advance.

Have you used std::cin before getting to that line? There may be a newline left in the input buffer. You can get rid of it with std::cin.ignore().
wow that worked! thank you!
Topic archived. No new replies allowed.