In many answers and questions such as this one, it is recommended to use cin.getline
from <string>
and not getline(cin, variable)
:
#include <iostream>
#include <string>
using namespace std;
int main() {
string name;
cin.getline(name);
}
But in my case I have build issue:
g++ foo.cpp
foo.cpp: In function ‘int main()’:
foo.cpp:8:21: error: no matching function for call to
‘std::basic_istream<char>::getline(std::string&)’
8 | cin.getline(name);
| ^