| | |
Size of string object???
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
>Its always priniting output as 16. Why is it like that?
Because that's the actual size of the object. The implementation probably looks something like this:
Where _buftype is likely defined as something along these lines:
The actual size of the string data itself is dynamic, so sizeof won't tell you how much memory has been allocated to the string. You can find that with the capacity member function.
Because that's the actual size of the object. The implementation probably looks something like this:
C++ Syntax (Toggle Plain Text)
template <class T, class Traits = char_traits<T>, class Alloc = allocator<T> > class basic_string { public: // Lots and lots of interface stuff private: size_type size; // Probably a 32-bit type size_type capacity; // Probably a 32-bit type _buf_type buffer; };
C++ Syntax (Toggle Plain Text)
struct _buf_type { T *base; // Beginning of buffer T *mark; // Helper pointer within buffer };
I'm here to prove you wrong.
Yes, you find the manual / help pages which describe the string class.
This will detail the public interface to the class.
Say perhaps
This will detail the public interface to the class.
Say perhaps
C++ Syntax (Toggle Plain Text)
string foo; foo.length();
Both the length and size member functions will give you the length of the actual string. Why are there two functions that do the same thing? That's the effect of taking an existing (pre-standard) class and forcing it to fit within the new standard definition of a container class. There are lots of ways the string class is poorly designed, and this is one of them.
Last edited by Narue; Jul 5th, 2006 at 9:26 am.
I'm here to prove you wrong.
![]() |
Similar Threads
- String to Object (Java)
- how to generate all k-1 size substrings from a k size string? (Python)
- making a string .. name of an object (Java)
Other Threads in the C++ Forum
- Previous Thread: Connecting C++ to Oracle
- Next Thread: inheritance, polymorphism, and other features
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






