如何修复“无重载函数实例"? cin.getline错误? [英] How do I fix a "No instance of overloaded function" error with cin.getline?
本文介绍了如何修复“无重载函数实例"? cin.getline错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
string add_text()
{
const int string_size(30);
string add_string;
cin.getline (add_string,string_size,'\n');
return add_string;
}
使用上面的函数编译程序时,出现错误.请注意,我在程序的前面使用了using namespace std;
.如果有帮助,我正在使用代码块,并且还尝试使用Visual Studio 11 Professional Beta来编译程序.
When I compile the program with the function above, I get an error. Note that I am using using namespace std;
earlier in the program. If it helps I am using Code Blocks and have also tried compiling the program using the Visual Studio 11 Professional Beta.
错误:
C:\Users\Jonathan\Documents\Code_Blocks\test_12\main.cpp|32|error: no matching function for call to 'std::basic_istream<char, std::char_traits<char> ::getline(std::string&, const int&, char)'|
在此问题上的任何帮助将不胜感激,在此先感谢您!
Any help with this issue will be greatly appreciated, thanks in advance!
推荐答案
You're calling std::istream::getline(char *, streamsize) - you can see it requires a char *
instead of the std::string
you're passing.
使用 std :: getline(std :: istream& ;、 std :: string& ;,char),就像这样:
getline(cin, add_string, '\n');
这篇关于如何修复“无重载函数实例"? cin.getline错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文