constant string array

This is a discussion on constant string array within the C++ Programming forums, part of the General Programming Boards category; hello! i'm trying to define array of strings, but i havent figured out how.. point is that later i need ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    8

    constant string array

    hello! i'm trying to define array of strings, but i havent figured out how..

    point is that later i need to printf("%s", strings[x]) all strings out (x is line no.)

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    const int NrOfStrings = 3;
    const char* const StringArray[NrOfStrings] =
    {
      "Hello",
      "World",
      "!",
    };
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,802
    How about this
    Code:
    #include <iostream>
    #include <string>
    const int NUM_OF_STRINGS = 4;
    int main()
    {
        const std::string myStrings[NUM_OF_STRINGS] = 
        {
            "Hello",
            "How",
            "Are",
            "you?"
        };
        for(int i = 0; i < NUM_OF_STRINGS; i++)
        {
            std::cout<<myStrings[i]<<" ";
        }
        std::cout<<std::endl;
        std::cin.get();
        return 0;    
    }
    Woop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer to array of string and Array of Pointer to String
    By vb.bajpai in forum C Programming
    Replies: 2
    Last Post: 06-15-2007, 06:04 AM
  2. Copying a string, into a string array.
    By m.mixon in forum C Programming
    Replies: 5
    Last Post: 07-31-2006, 05:19 PM
  3. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21