-
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? :confused:
Anyone who can give me a good advice, and a reason to their advice?
-
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.
-
In this example, std::string is a good solution.
Kuphryn