我的编译器不允许我使用 getline
My compiler wont let me use getline
当我尝试访问getline时,它会给我这样的错误!我想做的只是创建一个单独的简单文本。
C:\c++3+\Strings\main.cpp|11|error: 没有匹配函数调用 'getline(std::istream&, std::string&, const char [2])'|
#include <iostream>
#include <string>
using namespace std;
int main()
{
string last,name,playerclass;
getline(cin, last, ",");
getline(cin, name, ",");
getline(cin, playerclass, ",");
cout << name << last << " Is a " << playerclass;
return 0;
}
getline将单个字符作为分隔符的最后一个参数。你必须使用
std::getline( cin, last, ',' );
( ' 代替 " )
编译器的错误:
no matching function for call to 'getline(std::istream&, std::string&, const char [2])
它告诉您编译器试图找到一个将最后一个参数作为字符串(大小为 2 的文字字符串)的相应函数,但失败了。
相关文章:
- 为什么在我的函数类型后使用引用运算符 (&) 允许我修改它返回的值?
- std::带有自定义缓冲区的 iostream 不允许我写入
- Visual Studio 2017 不允许我创建 C++ 专用模板
- 为什么在指向对象的迭代器上调用函数不允许我更改对象本身?
- 错误:从"int"到"int*"的转换无效[-允许].我在下面提供了我的代码,我
- C++ 我的开关格式中的循环不允许我显示菜单选项或接受输入?
- 为什么Visual Studio(2017;15.7.5)不允许我更改c ++关键字颜色
- HTTP POST 请求不允许我定义上下文类型
- 如何创建一个接口,允许我访问C++中的按钮(和其他ui)函数,该函数是使用python中的MFC实现的
- Bazel 允许我包含来自全局安装库的标头
- 为什么Visual Studio允许我在模板函数中使用私有成员(C++)?
- 新版本的 SDL 不允许我使用SDL_image
- 为什么C++不允许我在类中使用字符串作为数据成员?
- 为什么此代码不允许我接收整个数组?
- 为什么 C 允许我调用未声明的函数?
- 如何允许我的程序成功读取数字包含的文件
- 为什么我允许我为std :: vector设置end()
- 如果不允许我分配 rvalues 来引用为什么以下代码片段有效,这在内部如何工作?
- c++getline函数不允许我输入
- 我的编译器不允许我使用 getline