vector<type,type>

N

nosbor

Hi
i have defined

typedef vector<string,bool> list_check;

how do i add elements to list_check ?

normally i would just use vector<type> , but am wondering if there is
a way to add things to list_check type.

would be nice to be able to do:

list_check.push_back("some_string",true);

but i get errors.

list_check lc();

compiles of , its when i try to add things to it i get more strange
errors.
help appreciated.
 
Z

zr

Hi
i have defined

typedef vector<string,bool> list_check;

how do i add elements to list_check ?

normally i would just use vector<type> , but am wondering if there is
a way to add things to list_check type.

would be nice to be able to do:

list_check.push_back("some_string",true);

but i get errors.

list_check lc();

compiles of , its when i try to add things to it i get more strange
errors.
help appreciated.

If you intend to map an index to a pair of a (string,bool) you could
do the following:
typedef pair<string, bool> pairCheck;
typedef vector<pairCheck> list_check; // Wouldn't vector_check be a
better name?

Add item using the following:
list_check.push_back(make_pair(string("some_string"),true));
 
N

nosbor

thanks for your reply. at least now i have an idea why it does not
work.

i have a list of strings, and i want to go through them one by one.
once i have processed each string i just want to mark it via "true",
just so that i know its been checked. hence the idea of <string,bool>
type

i can do this with make_pair of i could create another type that
contains members of vector and bool, and then use this type in another
vector.

thanks for your swift reply.


andy
 
R

red floyd

nosbor said:
thanks for your reply. at least now i have an idea why it does not
work.

i have a list of strings, and i want to go through them one by one.
once i have processed each string i just want to mark it via "true",
just so that i know its been checked. hence the idea of <string,bool>
type

i can do this with make_pair of i could create another type that
contains members of vector and bool, and then use this type in another
vector.

Use std::map<std::string, bool>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top