EN
C++ - get number of bytes allocated by std::string in memory
1 answers
8 points
Is it posible to check how many bytes uses std::string
object in c++?
1 answer
1 points
Yes, it is.
Use size_t capacity()
function.
Check this code:
xxxxxxxxxx
1
2
3
4
int main ()
5
{
6
std::string test("Some text here ...");
7
std::cout << "Capacity: " << test.capacity() << " bytes.\n";
8
return 0;
9
}
Output:
xxxxxxxxxx
1
Capacity: 18 bytes.
0 commentsShow commentsAdd comment