Feb 16, 2017 at 8:50pm Feb 16, 2017 at 8:50pm UTC
i have a question regarding vector about having multiple info.
for example if i have a file that contained firstName lastName and numbers
if i do i: V.insert(V.begin() + first, last, numbers) is that correct way ?
can you even allow to do it like that?
Last edited on Feb 16, 2017 at 8:51pm Feb 16, 2017 at 8:51pm UTC
Feb 16, 2017 at 9:08pm Feb 16, 2017 at 9:08pm UTC
can you even allow to do it like that?
No. You're misusing the comma operator.
Use a struct and push_back() the struct onto the vector.
1 2 3 4 5 6 7 8 9 10 11
struct person
{ string firstname;
string lastname;
int numbers; // Or whatever type this is
};
person p;
p.firstname = "Fred" ;
p.lastname = "Flintstone" ;
p.numbers = 1234;
V.push_back (p);
Last edited on Feb 16, 2017 at 9:09pm Feb 16, 2017 at 9:09pm UTC
Feb 16, 2017 at 9:14pm Feb 16, 2017 at 9:14pm UTC
@abstractionAnon
i havent learn struct yet and we are only allow to use vector.
Feb 16, 2017 at 9:26pm Feb 16, 2017 at 9:26pm UTC
Then use 3 vectors.
1 2 3 4 5 6 7
vector<string> firstname;
vector<string> lastname;
vector<string> numbers;
firstname.push_back ("Fred" );
lastname.push_back ("Flintstone" );
numbers.push_back ("123-45-6789" );
Last edited on Feb 16, 2017 at 9:29pm Feb 16, 2017 at 9:29pm UTC