std::list<std::vector<char>> myList;
std::vector<>
is the c++ way to correctly handle dynamic arrays. Rarely should you need to use new T[42]
directly to create an array.
std::vector<char> vc;
char ansi_str[] = &vc[0];
ansi_str
in the code above is defined by the C++03 standard to be the address of the first element in the array (in C++98 it was allowed to return a proxy).
If you really want to use your AnsiStrings
as strings you'd be better off using std::string
instead of std::vector<char>
. Then you'll get all of C++ nice string features for free and you'll still be able to access the raw data with std::string::data()
. The one disadvantage to using std::string
is the raw data is not available for modification. If your AnsiStrings
api needs to modify the data you'll be stuck with std::vector
.