简体   繁体   English

错误没有重载的实例 function “getline” 与参数列表匹配

[英]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:查看这些线程:

  1. Using getline(cin, s) after cin 在 cin 之后使用 getline(cin, s)
  2. Why does std::getline() skip input after a formatted extraction? 为什么在格式化提取后 std::getline() 会跳过输入?
  3. cin and getline skipping input cin 和 getline 跳过输入

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有重载函数的实例“getline”匹配参数列表 - no instance of overloaded function “getline” matches argument list 错误没有重载函数的实例“getline”匹配参数列表c ++ - error no instance of overloaded function “getline” matches the argument list c++ getline在C ++中使用字符串返回错误:没有重载函数getline的实例与参数列表匹配 - getline using strings in C++ returning error: No instance of overloaded function getline matches the argument list C ++没有重载函数getline的实例匹配参数列表 - C++ No instance of overloaded function getline matches argument list C++ 'getline' 没有重载的实例 function 匹配参数列表 - C++ 'getline' No instance of overloaded function matches argument list 错误:没有重载 function “std::getline”实例与参数列表匹配 — 参数类型为:(std::istream, char [50]) - Error: No instance of overloaded function “std::getline” matches the argument list — argument types are: (std::istream, char [50]) 为什么我收到错误:没有重载的 function “getline”实例与此处的参数列表匹配? - why am I getting a error: no instance of an overloaded function "getline" matches the argument list here? 没有重载函数“”的实例与参数列表错误匹配 - no instance of overloaded function “” matches the argument list error 当使用带有int的getline时,如何修复“没有重载函数的实例”getline“匹配参数列表” - How to fix “no instance of overloaded function ”getline“ matches the argument list” when using getline with an int getline() 不采用分隔符参数(错误:没有重载的实例 function “getline”匹配参数列表 - getline() not taking delimiter argument (ERROR: no instane of overloaded function "getline" matches argument list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM