using structures to assign unique values to words?

This is a discussion on using structures to assign unique values to words? within the C++ Programming forums, part of the General Programming Boards category; Ok, I need to assign unique values to words. Like say for instance the word "business" has a value of ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    18

    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
    Posts
    18
    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
    Posts
    7,328
    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
    Posts
    1,901
    Look into Maps, they do exactly that

    http://www.cppreference.com/cppmap/index.html

    just declare
    Code:
    #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, 09:01 AM
  3. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 07:00 PM
  4. extracting words from an array of words
    By axon in forum C++ Programming
    Replies: 2
    Last Post: 04-02-2003, 10:21 PM

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