C ++: Doubt with getline ()

0

I am learning C ++ and in the book I am reading it explains (a bit above) how to use the getline () function, so I wrote this code to test it:

#include <iostream>
#include <string>
using namespace std;

main ()
{
   string prueba;
   getline(cin, prueba, ",");
   cout << prueba;
}

The problem is that this error is thrown at me by the build messages (I am using Code: Blocks as IDE and MinGw as a compiler):

error: no matching function for call to 'getline((std:istream&, std::__cxxll::string&,...

(The error is on line 9)

    
asked by MahaSaka 11.12.2017 в 20:56
source

1 answer

2

The prototype is very clear

template< class CharT, class Traits, class Allocator>
std::basic_istream<CharT,Traits>& getline( 
    std::basic_istream<CharT,Traits>& input, 
    std::basic_string<CharT,Traits,Allocator>& str,
   CharT delim
);

Notice the first argument of the template (the last argument of the function:) charT (which, for std::string , is a char You, however, are using a char * .

Change your code to

getline( cin, prueba, ',' );
//                    ^

See the change: double quotes ( " ) for single quotes ( ' ).

    
answered by 11.12.2017 / 21:16
source