没有用于调用vector的匹配函数..找到C ++

时间:2014-10-09 22:29:02

标签: c++ vector

我已经完成了大约5次代码,我正在学习c ++,据我所知,一切都应该工作但是没有发生。错误毫无意义,我的意思是矢量假设有“at”函数..

我收到错误

In function 'void lookup(class vector<Customer,_default_alloc_template<false,0> > &, class string)': findByZipCode.cpp:30: no matching function for call to 'vector<Customer,_default_alloc_template,0> >::at (int)

findByZipCode.cpp

#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include "customer.h"

using namespace std;

Name readRestOfName(istream &in,string f) {
    string g;
    getline(in,g);
    Name abc (g,f);
    return abc;
}

Address readAddress(istream &in) {
    string street, city, state, zip;
    getline(in, street);
    getline(in, city);
    getline(in, state);
    getline(in, zip);
    Address abc (street, city, state, zip);
    return abc;
}

void lookup(vector<Customer>& v, string zip) {
    // COMPLETE
    vector <int> matches;
    cout<<v.at(2).getName()<<endl; <<<---------------error here!!!

}

int main() {
    // open customerdata file
    ifstream in("customerdata");
    vector<Customer> v;
    string f;

    while (getline(in,f)) {
        Name n = readRestOfName(in,f);
        Address a = readAddress(in);
        Customer abc(n,a);
        v.push_back(abc);
    }
    in.close();


string zip;
    while(!cin.fail()){
        cin>>zip;
        lookup(v,zip);
    }

    return 0;
}

customer.cpp和customer.h

的.cpp

#include <iostream>
#include "customer.h"
#include <string>
using namespace std;

string Customer::getName() {return n.getFamily() + ", " + n.getGiven();}
string Customer::getAddress() {return a.getStreet() + " " + a.getCity() + " "+ a.getState()+" "+a.getZip();}
string Customer::getZip() {return a.getZip();}

·H

#ifndef CUSTOMER_H
#define CUSTOMER_H
#include <string>
#include <iostream>
#include "name.h"
#include "address.h"


class Customer {
    private:
        Name n;
        Address a;
    public:
        Customer(Name b,Address c): n(b), a(c) {}
        std::string getName();
        std::string getAddress();
        std::string getZip();
};

#endif

0 个答案:

没有答案