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.
Printable View
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.
Use std::vector instead of using arrays; it'll make your memory
allocation much simpler....
Code:vector<vector<string> > stringTable;
Here is one solution.
Remember to deallocate the memory when you are done.Code:char **array = new char[10];
for (int i = 0; i < 10; ++i)
array[i] = new char[100];
Kuphryn
i think he only wants thisQuote:
Originally posted by PaulWendt
Use std::vector instead of using arrays; it'll make your memory
allocation much simpler....
Code:vector<vector<string> > stringTable;
Code:vector<string> ArrayOfStrings;
Yeah, he gave contradictory statements, I guess. In English, heQuote:
Originally posted by ncf
i think he only wants this
Code:vector<string> ArrayOfStrings;
said he wanted an array of strings, but his code snippet
imples a 2-dimensional array of strings.Code:string[10][100];
Perhaps he really meant to type:
<shrug>Code:char[10][100];
--Paul