std::getline
is not used as you are trying to use it. (I think you just made a typo by using >>
instead of ,
.)
You need to call it like this:
std::string getlinetest;
std::cout << "What is the string?" << std::endl;
std::getline(std::cin, getlinetest);
std::cout << getlinetest << std::endl;
PS:
And I don't get any sense behind using cin >> getlinetest;
before using getline
. If you want to remove preceding whitespaces, then you probably need to use std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
instead of putting a cin
statement before.
Check out these threads:
- Using getline(cin, s) after cin
- Why does std::getline() skip input after a formatted extraction?
- cin and getline skipping input