954,153 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

What wrong with this code?

What wrong with this code?

#include
#include
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;
}

StephanJos
Newbie Poster
9 posts since Oct 2008
Reputation Points: 6
Solved Threads: 0
 

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!)

Sci@phy
Posting Whiz in Training
279 posts since Sep 2008
Reputation Points: 110
Solved Threads: 43
 

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

chococrack
Junior Poster
149 posts since Oct 2008
Reputation Points: 92
Solved Threads: 16
 

Check your printf you havnt used the correct specifier

kenji
Junior Poster
145 posts since May 2008
Reputation Points: 11
Solved Threads: 11
 

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

kenji
Junior Poster
145 posts since May 2008
Reputation Points: 11
Solved Threads: 11
 

change

printf("%d",d);


to

printf("%s", d.c_str());
ivailosp
Junior Poster
129 posts since Apr 2008
Reputation Points: 21
Solved Threads: 22
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You