【问题标题】:My compiler wont let me use getline我的编译器不允许我使用 getline
【发布时间】:2014-12-24 02:56:08
【问题描述】:

当我尝试访问 getline 时,它​​会给我这样的错误!我要做的就是创建一个简单的分隔文本。

C:\c++3+\Strings\main.cpp|11|error: no matching function for call to '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;
}

【问题讨论】:

    标签: c++


    【解决方案1】:

    getline 将单个字符作为分隔符的最后一个参数。你必须使用

    std::getline( cin, last, ',' );
    

    ( ' 而不是 " )

    编译器的错误:

    no matching function for call to 'getline(std::istream&amp;, std::string&amp;, const char [2])

    它告诉你编译器试图找到一个对应的函数,最后一个参数为字符串(大小为 2 的文字字符串)但失败了。

    【讨论】:

    • 别担心,我认为这种情况经常发生:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-06
    • 1970-01-01
    • 1970-01-01
    • 2018-10-27
    相关资源
    最近更新 更多