Thread: STL Vectors

  1. #1
    Politics&Cpp geek Da-Nuka's Avatar
    Join Date
    Oct 2004
    Posts
    104

    STL Vectors

    Hi.
    I am making a windows-chat program, which shall naturaly contain a lot of textStrings, and a lot of window procedures...
    Making a lot of global CHAR arrays and corresponding int variables to keep track of what index number im working on with each variable will turn into a total mess.

    I am thinking about Structs, STL Vectors and classes.
    I think STL Vectors sounds tempting, but whats the good stuff, and whats the drawbacks about STL Vectors?

    Anyone who can give me a good advice, and a reason to their advice?

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Sounds like you want an std::map.
    Code:
    std::map<std::string, std::string> StringMap;
    
    StringMap.insert(std::make_pair("msg1", "Welcome to my chat program!"));
    StringMap.insert(std::make_pair("msg2", "Feel free to look around!"));
    StringMap.insert(std::make_pair("msg3", "See you next time!"));
    
    std::cout << StringMap["msg1"] << std::endl;
    Note that maps have O(log n) random access complexity as opposed to the O(1) random access complexity of std::vector.
    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
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    In this example, std::string is a good solution.

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sets of Vectors in STL
    By Steff in forum C++ Programming
    Replies: 8
    Last Post: 06-18-2009, 12:03 AM
  2. STL Vectors of Vectors
    By Beamu in forum C++ Programming
    Replies: 2
    Last Post: 12-31-2008, 05:23 AM
  3. allocating structs within STL vectors
    By aoiOnline in forum C++ Programming
    Replies: 20
    Last Post: 12-05-2007, 02:49 PM
  4. Array of Vectors amd other STL questions
    By kolistivra in forum C++ Programming
    Replies: 16
    Last Post: 04-12-2007, 09:11 AM
  5. STL vectors
    By sand_man in forum C++ Programming
    Replies: 7
    Last Post: 12-06-2005, 01:39 AM