How do I?

This is a discussion on How do I? within the C++ Programming forums, part of the General Programming Boards category; I defined an array of String (not string) String dictionary{"hello", "Goodbye"....}; How do I refer to each String, i.e the ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    20

    How do I?

    I defined an array of String (not string)
    String dictionary{"hello", "Goodbye"....};

    How do I refer to each String, i.e the word hello.
    I was trying something like
    word = dictionary[1];
    hoping to get hello, but got the first letter 'h' only.

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    You want something like -

    String dictionary [] = {"hello", "Goodbye"....};
    String word = dictionary[0];

  3. #3
    Ryce
    Guest

    heres one

    i duno if the last reply would work but here is what i would think would work.

    you need space to store letters, and space to hold each word

    char dictionary[256][10] = {"can hold 256 charecters","and 8 more words includeing this"};

    but its only an idea

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    20

    Thanks however

    One thing I don't understand is, I use a seperate unit for the dictionary array. Then I declare:

    #include "dictionary.h"

    extern String dictionary;
    String word = dictionary[1];

    it only gives me the h again!

    While declaring the dictionary in the same unit works fine. what am I doing wrong?

  5. #5
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Try -

    extern String dictionary[];

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Maybe?

    extern String dictionary[];

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    hehe, just a tad too slow...

  8. #8
    Registered User
    Join Date
    Jan 2002
    Posts
    20
    you guys are the best

Popular pages Recent additions subscribe to a feed

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