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

Adam G

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;
}
0x5453

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I am having trouble using command prompt for java program execution

I am having trouble with the .compareTo function

I am having trouble starting my node app in Bluemix

I am having trouble understanding the flow of programming

I am having trouble with this piece of code

I am having trouble with my Calculator

I am having trouble understanding IBM procedures

I am having trouble upcasing or capitalizing

Why am I having trouble writing to an array

I am having trouble understanding pipes and their implememnation in xv6

I am having trouble running my app

Why am I having so much trouble submitting my app to Apple?

I am having trouble with HTML Javascript inclusion

I am having trouble with function parameters

I am having trouble as a newbie with C++

I am having trouble syncing a local repository with git hub

I am having trouble with ASYNCTASK in my fragment

Why am I having trouble accessing SSL certificates working with Node.js/Express-TypeScript?

I am having trouble saving in a list integers taken from a file

I am having trouble understanding why I am not able to .map over the data I am return in the state that I set up in my React program

Animating a svg, with a mask, I am having trouble clipping outside of the svg

I am having trouble with my route in laravel

I am having a trouble importing the PyDictionary library

I am having trouble with OpenMP on C

I am having trouble updating node and npm

Why is there no server.emit in this code and i am having trouble understanding this code in node js?

I am a beginner and I'm having trouble compiling a simple program

I am having trouble organising boxes in css

I am having trouble getting the below fixed