Problem wit std::string::substr

  • Thread starter Thread starter Jarek Bednarz
  • Start date Start date
J

Jarek Bednarz

Hi all,
Following code causes strAddress to contain garbage data.
When I decrease number of characters that appear before '\\' then everything
is ok.
12 chars before '\\' seems to be a magic number.
I have compiled it with VisualStudio 2003.
Any ideas?

std::string strAddress = "123456789012\\aaaaa";
std::string::size_type pos = strAddress.find('\\');
if( pos != std::string::npos )
{
strAddress = strAddress.substr( pos + 1, 2 );
}

Thanks in advance for any help.
Jarek
 
Jarek said:
Hi all,
Following code causes strAddress to contain garbage data.
When I decrease number of characters that appear before '\\' then
everything is ok.
12 chars before '\\' seems to be a magic number.
I have compiled it with VisualStudio 2003.
Any ideas?

Show what you're really doing - the code snippet you provided works just
fine when I try it with VC7.1 (VS.NET 2003). Are you perhaps looking at
strings in the debugger and not seeing what you're expecting? If so, that's
a known debugger bug related to the "small string optimization" that's
implemented in the VC7.1 runtime library.

-cd
 
Hello Daniel,
Thanks a lot for a hint.
I was looking only at the debugger results and wondering what's going on.
I didn't know about this debugger bug. In fact std::string contains proper
value, only the debugger is fooling around.

Jarek
 
Back
Top