Usage of std::string.append causes "Stack around the variable 'result' was corrupted"

Posted by Yan Cheng CHEOK on Stack Overflow See other posts from Stack Overflow or by Yan Cheng CHEOK
Published on 2010-03-24T03:57:16Z Indexed on 2010/03/24 4:03 UTC
Read the original article Hit count: 214

Filed under:

I have the following code :

std::string Utils::get() {
    std::string result;
    result.append(1, 'x');
    result.append(1, 'x');
    result.append(1, 'x');
    return result;
}

I expect 'xxx' to be returned.

However, when I run under debug mode, I get the warning

"Stack around the variable 'result' was corrupted"

Am I using append function the wrong way?

© Stack Overflow or respective owner

Related posts about c++