0

I'm using GeeksForGeeks ReadCSV function to read CSV files, I copied the code exactly as it is and I get this error: "no instance of "getline" matches the argument list" can anyone provide me with why it happens?

Here's the full code:

void ReadCSV(std::string filename, std::vector<RowVector*>& data)
{
    data.clear();
    std::ifstream file(filename);
    std::string line, word;
    // determine number of columns in file
    getline(file, line, '\n');
    std::stringstream ss(line);
    std::vector<Scalar> parsed_vec;
    while (getline(ss, word, ', ')) {
        parsed_vec.push_back(Scalar(std::stof(&word[0])));
    }
    uint cols = parsed_vec.size();
    data.push_back(new RowVector(cols));
    for (uint i = 0; i < cols; i++) {
        data.back()->coeffRef(1, i) = parsed_vec[i];
    }

    // read the file
    if (file.is_open()) {
        while (getline(file, line, '\n')) {
            std::stringstream ss(line);
            data.push_back(new RowVector(1, cols));
            uint i = 0;
            while (getline(ss, word, ', ')) {
                data.back()->coeffRef(i) = Scalar(std::stof(&word[0]));
                i++;
            }
        }
    }
}
yarin Cohen
  • 995
  • 1
  • 13
  • 39

1 Answers1

1

The third argument for getline is a single character (see below). When you pass it ', ' you are trying to pass two characters in single quotes.

https://www.cplusplus.com/reference/string/string/getline/

istream& getline (istream& is, string& str, char delim);

Change your delimiter to just ',' (a single character) and you should be fine.

In case you're interested in single vs. double quotes, and what happens when you put more than one character in single quotes, the following post has some good discussion. (Single quotes vs. double quotes in C or C++)

Sean
  • 49
  • 4