Thread: STL Vectors

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

    STL Vectors

    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
    Sounds like you want an std::map.
    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.

    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
    In this example, std::string is a good solution.


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