Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

storing int and string in a vector

Status
Not open for further replies.

BashmentGirl

Technical User
Apr 4, 2002
3
US
Can anyone give me a suggestion on how to store string and int in the same vector, if possible?
 
you could store both,

union xxx
{
int x;
char* y;
}

...
vector<xxx>....

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
With the union, you still have to know which one is &quot;in use.&quot; So you'd still need that union within a struct, which has another member telling which one is in use.

And the union solution only works if you're using a char*. If you're using a string object (Standard or otherwise), it won't.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top