-1

I'm basicly trying to tokenize a string from a file and create an object using the tokens as parameters for the object.

I need to be able to make a new object for each line in the file.

But I get the error no viable overloaded '='

 string tokens[8];
int i =0;
int j=0;


vector<Package *> myPack[5];

while (file.good()){
    getline(file,buffer);
    cout<< buffer<< endl;

    string token, text(buffer);
    istringstream iss(text);
    cout <<endl;
        while (getline(iss, token, '|')){
            cout << token << endl;
            tokens[i]=token;
            i++;
}

myPack[0] = new Package(tokens[0] ,tokens[1],tokens[2],tokens[3], stod(tokens[4]), stod(tokens[5]));
j++;
}

error occurs here

  myPack[0] = new Package(tokens[0] ,tokens[1],tokens[2],tokens[3], stod(tokens[4]), stod(tokens[5]));

2 Answers 2

1

vector<Package *> myPack[5]; is an array of five (empty) vectors, not a vector with five Package* elements.

The latter looks like vector<Package *> myPack(5);.

1
  • Thank you so much! that was the problem.
    – obsi
    Jul 12, 2015 at 20:35
0

Your myPack vector has a length of 0, so myPack[0] (accessing the first element in the vector) is an error.

You have to push_back your Package object to insert it.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.