Adam G
Adam G

Reputation: 165

Why am I having trouble with getline()? "No instance of overloaded functions matches the argument list" and "data is ambiguous"

I've used this exact function before, but simply copy and pasting it to another file has caused it to stop working. The only change is that i added "using namespace std".

In my "ReadData()" function, I'm getting an error on getline(cin, data) that no instance of overloaded functions matches the argument list. Also, I'm getting an error on "data" in the call, saying "data is ambiguous."

The function is supposed to read data from a text file and store the line of text in data for further processing. This function has worked exactly how it is so I'm just not sure.

#include <iostream>
#include "NvraArray.h"
#include "NvraRecord.h"

#include <vector>
#include <string>
#include <ctime>
using namespace std;

// Globals
string data; // Stores the line that getline is at
vector<string> rows; // Stores the rows of data
vector<int> recordNumbersSeen; // Holds records numbers that have been checked
string strWords[24]; // Holds the individual columns of data for processing
int rowCounter = 0; // Counts the rows of data coming in

// Prototypes
// Reads the data from cin into the "rows" vector
void ReadData();
// Checks the current row against the list of records already seen
bool isDuplicate(int recordID);
// Checks the current row for invalid data
bool isValidData();
// Splits the row into an array to process
void SplitRowIntoArray(std::string row);

int main(){

    // For testing purposes
    srand(time(NULL));

    NvraArray array;
    NvraRecord record;



    system("pause");
    return 0;
}

void ReadData(){
    while(getline(cin,data)){

        // if on the first row, do nothing and skip to the next.
        if(rowCounter != 0){

            rows.push_back(data);
        }else{
            rowCounter++;   
        }
    }
    rowCounter = 0;
}

Upvotes: 2

Views: 2618

Answers (2)

ComicSansMS
ComicSansMS

Reputation: 54589

You run into a conflict with the std::data function template that was introduced with C++17. Apparently one of the standard library headers you're including pulls in an include to iterator.

Renaming your global variable to something other than data should fix the issue.

Upvotes: 5

0x5453
0x5453

Reputation: 13589

This is a prime example of why you shouldn't use using namespace std;. You have a name conflict: string data is conflicting with std::data.

If this is not enough to convince you, check out this list of some of the other names in the std namespace. If you use using namespace std;, any of these names could cause a collision if you happen to include the right headers.

Upvotes: 6

Related Questions