I'm constructing a string object by an initial assignment and a large number of concatenations (using the += operator). After the string gets to a certain size (not very big; about 350 bytes), a concatenation fails. My string ultimately needs to be several thousand bytes long.
I assumed that the string would automatically resize itself; is this incorrect?
Yes, I'm using std::string. I think the problem may be in the compiler (it's for an ARM processor, and may have an arbitrarily small limit pre-set for string lengths). I'll check with the vendor now that I know my assumption was good.
Here's a code fragment that should give you the idea:
Don't contact the vendor. The problem is in your code.
sscanf(buffer.c_str(),
c_str gives you a read only buffer to the string. By writing to it you are very likely stepping out of bounds of the string and corrupting memory. you must never ever ever do this.
I'm surprised this even compiled, as sscanf takes a char* and c_str clearly returns a const char*. It should have errored on you.
General rule: do not mix C string functions with C++ strings.