$ cat str.cpp
#include <iostream>
#include <string>
using namespace std;
int main(){
string s("hello world");
char* c;
int *size, *capacity, *shared;
c = (char*)s.c_str();
size = (int*)(c-12);
capacity = (int*)(c-8);
shared = (int*)(c-4);
cout << "size: " << *size << endl;
cout << "capacity: " << *capacity << endl;
cout << "shared: " << *shared << endl;
return 0;
}
$ g++ str.cpp ; ./a
size: 11
capacity: 11
shared: 0
What about another topic… C++ strings vs C strings.
What the heck is wrong with C strings? I understand C++ strings have a lot of features like buffer overflow protection and such, but whats
the point when you have to end up converting them back to C strings to use almost any of the existing functions?
PS: I have a lot of other MUD related topics I think would be interesting in a debate, do you guys think a regular series of debates would be
fun or would it end up being a flame war?