Problems with sstream/ icc bug?

Problems with sstream/ icc bug?


The following code produces unexpected results.
Am I wrong, or is this a icc bug?

I'm using icc version 7.1 under linux.

Here the code


int main()
std::ostringstream oss;
int no(-1);
oss << "state." << std::setw(4) << std::setfill('0') << no;
std::cout << oss.str().c_str() << std::endl;
const char *p = oss.str().c_str();
std::cout << p << std::endl;
return 0;

I expected the program to print
but p seems to point nowhere.
Any advice?

Christoph Behle

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The issue is with Dinkumware C++ Standard template library and not the compiler.

Please log this issue at Intel support site.



I see that your example works correctly with g++, even on Windows. I just installed 2 updated versions of the Intel compiler, and it continues to fail with p set as a null pointer. Compatibility with g++ (only on linux, not on Windows) is a stated goal for Intel compilers. You might file a report at


I apologize for posting such a stupid question.
My code is buggy, since oss.str().c_str()
returns a pointer to a temporary object.
My fault, again I apologize.

Christoph Behle

Leave a Comment

Please sign in to add a comment. Not a member? Join today