Thread: using structures to assign unique values to words?

  1. #1
    Registered User
    Join Date
    Nov 2006

    using structures to assign unique values to words?

    Ok, I need to assign unique values to words. Like say for instance the word "business" has a value of $%%^&*(*
    Is it possible to do by using structure variables?

  2. #2
    Registered User
    Join Date
    Nov 2006
    I would also need it when users input a word for the program to search the program for these unique words.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Sure. Use a struct that holds two strings, the word and its value. It would probably be better to put these in a map instead of a specific struct, with the word as the map key and the value as the value. This would also make lookup easy.

  4. #4
    Ethernal Noob
    Join Date
    Nov 2001
    Look into Maps, they do exactly that

    just declare
    #include <map>
    std::map<string, string> amap;   //initializes a map from key string to value of string.
    amap["business"]= "$%%^&*(*"
    it's basically a custom array, where the index, rather being of int or size_t, it is whatever is in the first type parameter of the declaration. The second would just be what the custom array holds.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginners Contest #2 For those who wanted more!!
    By ILoveVectors in forum Contests Board
    Replies: 16
    Last Post: 08-12-2005, 12:03 AM
  2. Problem with malloc() and sorting words from text file
    By goron350 in forum C Programming
    Replies: 11
    Last Post: 11-30-2004, 10:01 AM
  3. New Theme
    By XSquared in forum A Brief History of
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM
  4. extracting words from an array of words
    By axon in forum C++ Programming
    Replies: 2
    Last Post: 04-02-2003, 11:21 PM