|
-
October 3rd, 2002, 09:36 AM
#1
Dynamic Allocation of arrays of strings
I need to allocate and access an array of strings. I need to do the dynamic version of this: string[10][100] and access and use it.
-
October 3rd, 2002, 09:46 AM
#2
Use std::vector instead of using arrays; it'll make your memory
allocation much simpler....
Code:
vector<vector<string> > stringTable;
-
October 3rd, 2002, 01:47 PM
#3
Here is one solution.
Code:
char **array = new char[10];
for (int i = 0; i < 10; ++i)
array[i] = new char[100];
Remember to deallocate the memory when you are done.
Kuphryn
-
October 3rd, 2002, 01:53 PM
#4
Originally posted by PaulWendt
Use std::vector instead of using arrays; it'll make your memory
allocation much simpler....
Code:
vector<vector<string> > stringTable;
i think he only wants this
Code:
vector<string> ArrayOfStrings;
-
October 3rd, 2002, 03:19 PM
#5
Originally posted by ncf
i think he only wants this
Code:
vector<string> ArrayOfStrings;
Yeah, he gave contradictory statements, I guess. In English, he
said he wanted an array of strings, but his code snippet
imples a 2-dimensional array of strings.
Perhaps he really meant to type:
<shrug>
--Paul
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|