Heavy Metal
October 3rd, 2002, 09:36 AM
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.
|
Click to See Complete Forum and Search --> : Dynamic Allocation of arrays of strings Heavy Metal October 3rd, 2002, 09:36 AM 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. PaulWendt October 3rd, 2002, 09:46 AM Use std::vector instead of using arrays; it'll make your memory allocation much simpler.... vector<vector<string> > stringTable; kuphryn October 3rd, 2002, 01:47 PM Here is one solution. 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 ncf October 3rd, 2002, 01:53 PM Originally posted by PaulWendt Use std::vector instead of using arrays; it'll make your memory allocation much simpler.... vector<vector<string> > stringTable; i think he only wants this vector<string> ArrayOfStrings; PaulWendt October 3rd, 2002, 03:19 PM Originally posted by ncf i think he only wants this vector<string> ArrayOfStrings; Yeah, he gave contradictory statements, I guess. In English, he said he wanted an array of strings, but his code snippet string[10][100]; imples a 2-dimensional array of strings. Perhaps he really meant to type: char[10][100]; <shrug> --Paul codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |