I have this puny program.
#include <iostream>
#include <string>
int main()
{
std::string st = ('='+"10");
std::cout<<st<<"-"<<st.c_str();
return 0;
}
What sort of output you expect without running it?
I am getting : -
I am running into such problems while using boost::spirit library and passing its output around as c-strings.
Am I missing something? I am using gcc 4.6.1 (ubuntu 10.10).
This:
Probably does not do what you expect. Rather than concatenating, it will “add” (arithmetically) the “ASCII” value of ‘=’ to a pointer to the literal string “10”, which is a buffer overrun and so invokes undefined behavior.
If you run your program under valgrind you will likely see it complain about this.
Instead, try: