[英]Error No instance of overloaded function “getline” matches the argument list
I've searched this website and I have tried most things and they all don't work If anyone knows what I am doing wrong please help, This is my code.我已经搜索了这个网站,我已经尝试了大多数东西,但它们都不起作用如果有人知道我做错了什么,请帮忙,这是我的代码。
string getlinetest;
cout << "What is the string?" << endl;
cin >> getlinetest;
getline(cin >> getlinetest);
cout << getlinetest << endl;
std::getline
is not used as you are trying to use it. std::getline
在您尝试使用时未使用。 (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: PS:
And I don't get any sense behind using cin >> getlinetest;
而且我对使用
cin >> getlinetest;
没有任何意义。 before using getline
.在使用
getline
之前。 If you want to remove preceding whitespaces, then you probably need to use std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
如果要删除前面的空格,则可能需要使用
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
instead of putting a cin
statement before.而不是在前面放一个
cin
语句。
Check out these threads:查看这些线程:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.