David Morales
David Morales

Reputation: 57

My compiler wont let me use getline

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

Answers (1)

Nikko
Nikko

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

Related Questions