[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

nosbor

11/23/2008 8:03:00 PM

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.
6 Answers

Pete Becker

11/23/2008 8:10:00 PM

0

On 2008-11-23 15:02:52 -0500, nosbor <arobson73@yahoo.co.uk> said:

>
> typedef vector<string,bool> list_check;

This defines list_check as a specialization of vector that holds
elements of type string and uses the type bool as its allocator. Since
the type bool has very few, if any, of the properties required for an
allocator, it's not at all surprising that it doesn't work.

What are you trying to do?

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

zr

11/23/2008 8:29:00 PM

0

On Nov 23, 10:02 pm, nosbor <arobso...@yahoo.co.uk> wrote:
> 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));

nosbor

11/23/2008 9:14:00 PM

0

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

red floyd

11/24/2008 12:23:00 AM

0

nosbor wrote:
> 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>

Sam

11/24/2008 1:09:00 AM

0

red floyd writes:

> nosbor wrote:
>> 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>

That assumes that all of those strings are unique.

The answer that's more closer to the original question would be
std::vector<std::pair<std::string, bool> >


tommy.hinks

11/25/2008 10:40:00 AM

0

On Nov 24, 1:08 am, Sam <s...@email-scan.com> wrote:
> red floyd writes:
> > nosbor wrote:
> >> 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>
>
> That assumes that all of those strings are unique.

std::multimap allows keys that are not unique.

>
> The answer that's more closer to the original question would be
> std::vector<std::pair<std::string, bool> >
>

T