vector with struct and allocate memory

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
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
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?
Sorry my mistake, code struct been old.
I editet post. ;-)
Topic archived. No new replies allowed.