"Alex Tibbles" <al**********@yahoo.co.uk> wrote in message news:<40***********************@mercury.nildram.ne t>...
perhaps your debugger is not interpreting the string properly and just
printing its address (the stuff starting 0x...). gdb does this for
std::string cos it doesn't know that a std::string is a string.
I suspect that's the problem here. Your code seems correct, and
the value of the std::string is actually correct, but it looks
wrong in your debugger.
I've experienced this myself in Visual Studio 7, but it was fixed
in 7.1 if I recall correctly. The issue is that beginning in v 7,
the implementation of std::basic_string (from Dinkumware) used the
small string optimization. If you look at the source, you'll see
the following union:
union _Bxty
{ // storage for small buffer or pointer to larger one
_Elem _Buf[_BUF_SIZE];
_Elem *_Ptr;
} _Bx;
A short string is stored in _Buf, in which case _Ptr is garbage.
The debugger took a while to catch up with this. So in 7.0 (but
not IIRC in 7.1) the debugger only knew about _Ptr. So for a
small string, the debugger displayed the contents of a "random"
location.
<sop_to_OT_police>
If you think about it, this is kind of a tricky thing for a
debugger to get right so you may see similar behavior on other
implementations that use this technique.
</sop_to_OT_police> :-)