vector<char>
gives you a guarantee that &v[0]+n == &v[n]
whereas a string doesn't (practically, it is the case, but there is no guarantee)... AFAIK C++0x gives that guarantee already
- there is no implicit conversion from
const char*
to vector<char>
- string is not an STL container. For example, it has no
pop_back()
or back()
functions
- And last, but not least, different member functions! String gives you functions suitable for strings, like returnig a null-terminated string with
c_str()
Bottom line: Use string
when you need to operate with strings. Use vector<char>
when you need a ... well, vector of individual chars...
Another use of vector<char>
is a way to avoid vector<bool>
specialization.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…