What wrong with this code?

#include <sstream>
#include <string>
using namespace std;

int main()
{
    string a = ":)";
    string b = "John";
    int c = 2;
    string d;
    stringstream str;
    str << a << " Hello " << b << " bye " << c;
    d = str.str();
printf("%d",d);
getchar();
return 0;
}
Salem commented: Which get's you a smilie in the rep :( -4

Recommended Answers

All 5 Replies

d is c++ string object, and printf is C function.
Even more, not only it's C function (it would probably work nevertheless), but you've told it to print integer ( "%d" tells printf to print integer!)

Well it's dead obvious... theres a SMILEY FACE IN YOUR CODE! o.0

commented: Which get's you a smilie in the rep :) +23

Check your printf you havnt used the correct specifier

Check the printf your using the wrong format specifier also use the code tags.

change

printf("%d",d);

to

printf("%s", d.c_str());
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.