Hello, I'm having a problem adding values to a variable within a structure.
Here's a simplified version of my program(only with the part that isn't working)
On line 21 you are using a vector of dados, not a dados object. -The vector is empty there so you won't be able to use dados members until you don't add some objects to the vector-
On line 23 you are using the class name instead of the vector
line 21:
I don't understand what you mean, I'm trying to add "temp". I'm still new to this.
If i use the "vector <string> nome;" outside of the structure it works.
something like this:
1 2 3 4 5 6
vector<string>nome;
string temp;
cout<<"Qual o nome do Titular."<<endl;
getline(cin, temp);
nome.push_back(temp);
cout << nome[0];
ahh, i think I'm understanding what you're trying to say.
So something like this?
1 2 3 4 5
string temp;
cout<<"Qual o nome do Titular."<<endl;
getline(cin, temp);
contas[0].nome.push_back(temp);
cout << contas[0].nome[0] << endl;
This doesn't give me a compile error, but when i execute it, it terminates after i write something, probably accessing some invalid memory or something.
It appears that you are creating a vector of dados objects, which each contain a vector of strings. Is this what you need? Judging by the rest of the code, I wonder if one of the vectors is unnecessary.
Regardless, in nested container situations you have to add information from the outer-most container to the inner-most container. For example:
1 2 3 4 5 6 7 8 9
vector< vector<int> > v2;
//..
v2[0].pushback( 1 ); // error: v2 does not contain any elements (of type vector<int>)
//..
vector<int> temp;
temp.push_back( 1 ); // temp vector contains 1
v2.push_back( temp ); // now v2 contains a vector<int>, which contains 1.
//..
cout << v2.front().front() << endl; // outputs 1