Alright so I recently learned getline, from a tutorial and I looked it up for examples on this website and
This is the example provided from the website:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// istream getline
#include <iostream>
usingnamespace std;
int main () {
char name[256], title[256];
cout << "Enter your name: ";
cin.getline (name,256);
cout << "Enter your favourite movie: ";
cin.getline (title,256);
cout << name << "'s favourite movie is " << title;
return 0;
}
Using operator>>() to read from std::cin sucks. Its behavior is completely unintuitive: it always leaves a newline in the input buffer, so if you mix reading methods, something is bound to go wrong. Use exclusively getline(). In fact, I'd recommend std::getline() plus std::string.