String.size() & String.length() - Whats the difference??
String.size() and String.length() - Whats the difference??
i''ve been working with a lot of string conversion lately and i''m not excatly sure what the best function to use for determing the number of characters a string has... Can Anyone Explance the differences between these two.. C++ =)
For std::string, there is absolutely no difference, the two functions are the same.
[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI''s STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]
Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...
quote:Stroustrup, p586
The length() of a string is simply a synonym for its size(); both functions return the number of characters in the string. Note that they do not count a C-string-style, zero-terminator character (§20.4.1). An implementation of basic_string stores its length rather than relying on a terminator.
[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI''s STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]
Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...
quote:Original post by Fruny
For std::string, there is absolutely no difference, the two functions are the same.Stroustrup, p586
The length() of a string is simply a synonym for its size(); both functions return the number of characters in the string. Note that they do not count a C-string-style, zero-terminator character (§20.4.1). An implementation of basic_string stores its length rather than relying on a terminator.
Ahh Thank you!! Seems pretty dumb though. I guess i was thinking two different functions should have 2 differences.. at least 1 of them should maybe count the NULL at the end or something special.. but two of the same seems a bit pointless..
=)
People talking about strings tend to think about the length of the string. Algorithms working on containers tend to refer to the size of the container.
And yes, strings are STL containers;
[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI''s STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]
Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...
And yes, strings are STL containers;
[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI''s STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]
Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement