简体   繁体   中英

getline using strings in C++ returning error: No instance of overloaded function getline matches the argument list

I'm trying to parse a document using getline to take an entire line and place it in the string variable named 'line.' The problem is I'm getting an error that says: "No instance of overloaded function getline matches the argument list." Can anyone help me solve this problem?

#include <iostream>
#include <fstream>
#include <string>
#include "recordsOffice.h"

using namespace std;

RecordsOffice::RecordsOffice()
{

}

void RecordsOffice::parseCommands (string commandsFileName)
{
//String to hold a line from the file
string line;

//Open the file
ifstream myFile;
myFile.open(commandsFileName);

// Check to make sure the file opened properly
if (!myFile.is_open())
{
    cout << "There was an error opening " << commandsFileName << "." << endl;
    return;
}

//Parse the document
while (getline(myFile, line, '/n'))
{
    if (line[0] == 'A')
    {
        addStudent(line);
    }

Your escape sequence is backward - try replacing

/n

With

\n

Multicharacter character liberals in C++ have type int , rather than type char , which is causing the arguments to std::getline to have the wrong type. (Thanks to @chris for pointing out that the type will be int specifically!)

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM