Simple string question...

Started by
12 comments, last by Moe 22 years, 4 months ago
Technically, class string isn''t part of the STL, not being a template class and all But it does share much of the functionality, especially in the modifying functions and iterators. Nice thing about class string is most operators and functions are overloaded six way ''til Sunday to work with char-strings, single char''s and other string objects (10 versions of insert() alone). A must-learn.

Chris Barry

Jesus saves ... the rest of you take 2d4 fire damage.

Advertisement
actually it is a templated class, string is just a typedef for basic_string<char> or something like that.
You sure? I''m pretty sure class string'' methods are optimized for dealing with the entire string as one object, while vectors are optimized for managing each container individually. Hmmm. Well, I guess the standard doesn''t say they can''t make string a typedef of an STL container and add new funtionality .....

Chris Barry

Jesus saves ... the rest of you take 2d4 fire damage.

quote:Original post by 23yrold3yrold
I''m pretty sure class string'' methods are optimized for dealing with the entire string as one object, while vectors are optimized for managing each container individually.

?

*doesn''t get it*

Why are you using vector and string as comparable arguments? std::vector has nothing to do with std::string (which is a typedef for std::basic_string<char> btw); vector and string are are both containers and control sequences of data. That means there is little probability of similarity between them, because if there was one would simply be an adapter for the other.

Furthermore, std::string does not optimize anything - at least not in the popular Dinkumware implementation (which comes with MSVC). And according to this page, neither does the SGI implementation:
quote:basic_string<charT, traits, Alloc>:
The types string and wstring are typedefs for, respectively, basic_string<char> and basic_string<wchar_t>.


The SGI STL site is a good resource. You can find the link in my .sig

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!

This topic is closed to new replies.

Advertisement