为什么我遇到getline()?"没有重载函数的实例与参数列表匹配"和"数据不明确"

Ada*_*m G 0 c++ cin getline ambiguous

我之前使用过这个确切的函数,但只是复制并粘贴到另一个文件导致它停止工作.唯一的变化是我添加了"using namespace std".

在我的"ReadData()"函数中,我在getline(cin,data)上遇到一个错误,即没有重载函数的实例与参数列表匹配.此外,我在调用中的"数据"中收到错误,称"数据不明确".

该函数应该从文本文件中读取数据并将文本行存储在数据中以供进一步处理.这个功能确实如此,所以我只是不确定.

#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;
}
Run Code Online (Sandbox Code Playgroud)

Com*_*sMS 5

您遇到std::data与C++ 17引入的函数模板冲突.显然,您所包含的标准库标题之一是包含iterator.

将全局变量重命名为其他内容data应该可以解决问题.


0x5*_*453 5

这是您不应该使用的一个主要示例using namespace std;.你有一个名字冲突:string data与之相冲突std::data.

如果这还不足以说服你,看看一些在其他的名字列表std命名空间.如果您使用using namespace std;,如果碰巧包含正确的标题,这些名称中的任何一个都可能导致冲突.