I'm new to C++ and I can't figure out how to use cin (or any other method) to take a string input and store it in a variable. It's frustrating that it takes just the first word of a string.
It seems that my program ignores the getline() or cin.getline() , can somebody explain what is the diference and how should I use these?
I've also tryed scanf but that doesn't work either and just stores the first word of the input string in my variable.
This is my code :
#include <iostream>
using namespace std;
int main() {
int l;
double m;
string n;
cin >> l;
cin >> m;
getline(cin, n);
cout << "This is my int: " << l << endl;
cout << "This is my double: " << m << endl;
cout << "This is my string: " + n << endl;
return 0;
}