如何从文件C ++将数据推送到向量

问题描述

我在'.csv'文件中有一些数据表,我想将这些数据从该文件中推到向量中,我尝试了push_back,但是它对我没有用,我实际上是一个初学者c ++。有人可以帮我解决这个问题吗?

struct contacts {
    string name;
    string nickName;
    string phoneNumber;
    string carrier;
    string address;
};

vector <contacts> proContactFile;

这是我从文件中读取值的部分(下)

void readContactDetails() {
    ifstream ContactFile;
    ContactFile.open("Contact.csv");
    string readString;
    if (ContactFile) {

        while (!(ContactFile.eof())) {
            getline(ContactFile,readString); // Read the column headers
            for (int i = 0; i <= 10; i++) {
                getline(ContactFile,limit[i].name,','); // ',' is the separator
                getline(ContactFile,limit[i].nickName,');
                getline(ContactFile,limit[i].phoneNumber,limit[i].carrier,limit[i].address); // Read until the end of the line

            }
            proContactFile.push_back(ContactFile);
        }
    }
    else {
        cout << "Error"<< endl;//Show an error message if the file isn't opened
    }
}

它总是显示错误消息->

no instance of overloaded function "std::vector<_Ty,_Alloc>::push_back [with _Ty=contacts,_Alloc=std::allocator<contacts>]" matches the argument list 

有人可以告诉我这是怎么回事吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)