Reputation: 57
When ever i try to access getline it will give me an error like this! All I want to do is create a simple text seperated.
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;
}
Upvotes: 1
Views: 300
Reputation: 4252
getline takes a single char as last argument for delimiter. You have to use
std::getline( cin, last, ',' );
( ' instead of " )
The error of the compiler :
no matching function for call to 'getline(std::istream&, std::string&, const char [2])
It tells you that the compiler tried to find a corresponding function with last parameter as string ( literal string of size 2) but failed.
Upvotes: 7