CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2002
    Posts
    4

    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.

  2. #2
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347
    Use std::vector instead of using arrays; it'll make your memory
    allocation much simpler....
    Code:
    vector<vector<string> > stringTable;

  3. #3
    Join Date
    Feb 2002
    Posts
    5,757
    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

  4. #4
    Join Date
    Oct 2001
    Location
    California
    Posts
    27
    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;

  5. #5
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347
    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
    Code:
    string[10][100];
    imples a 2-dimensional array of strings.

    Perhaps he really meant to type:
    Code:
    char[10][100];
    <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
  •  





Click Here to Expand Forum to Full Width

Featured