vector with struct and allocate memory
Oct 2, 2009 at 5:51pm UTC
Hello.
I want to save in Struct element of type string. How i can save data in string with out error.
My struct is
1 2 3 4
typedef struct tagDD{
string tt;
int ii;
} DD;
code work if i hide line 'dd[i].tt = "a";'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
vector<DD> mv;
DD* dd;
int length = 256;
dd = mv.get_allocator().allocate(length);
for (int i=0; i<length; i++) {
dd[i].count=i;
// this i hide
// dd[i].tt = "a";
}
for (int i=0; i<length; i++)
cout << " " << dd[i].count;
cout << "\n\n" ;
mv.get_allocator().deallocate(dd, 5);
Last edited on Oct 3, 2009 at 2:18pm UTC
Oct 2, 2009 at 6:13pm UTC
I like this forum. When i search before write in forum cplusplus in net i do not find answer.
After it i find faster. This forum work's good :-)
1 2 3 4 5
typedef struct tagDD{
string tt;
int ii;
tagDD() { tt = "" ; ii = 0; }
} DD;
1 2
vector<DD> mv;
mv.resize(length);
*** But answering from my new question pleas. ***
Last edited on Oct 3, 2009 at 2:21pm UTC
Oct 2, 2009 at 7:07pm UTC
Your struct definition is basically creating a struct named DD, and then creating a sort of 'Nickname' for it under the name Dane. What are you trying to do with that, exactly?
Oct 3, 2009 at 2:20pm UTC
Sorry my mistake, code struct been old.
I editet post. ;-)
Topic archived. No new replies allowed.