943,774 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 534
  • C++ RSS
Oct 24th, 2008
-1

What wrong with this code?

Expand Post »
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;
}
Similar Threads
Reputation Points: 6
Solved Threads: 0
Newbie Poster
StephanJos is offline Offline
9 posts
since Oct 2008
Oct 24th, 2008
0

Re: What wrong with this code?

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!)
Reputation Points: 110
Solved Threads: 43
Posting Whiz in Training
Sci@phy is offline Offline
279 posts
since Sep 2008
Oct 25th, 2008
1

Re: What wrong with this code?

Well it's dead obvious... theres a SMILEY FACE IN YOUR CODE! o.0
Reputation Points: 92
Solved Threads: 16
Junior Poster
chococrack is offline Offline
149 posts
since Oct 2008
Oct 25th, 2008
0

Re: What wrong with this code?

Check your printf you havnt used the correct specifier
Reputation Points: 11
Solved Threads: 11
Junior Poster
kenji is offline Offline
145 posts
since May 2008
Oct 25th, 2008
0

Re: What wrong with this code?

Check the printf your using the wrong format specifier also use the code tags.
Reputation Points: 11
Solved Threads: 11
Junior Poster
kenji is offline Offline
145 posts
since May 2008
Oct 25th, 2008
0

Re: What wrong with this code?

change
cpp Syntax (Toggle Plain Text)
  1. printf("%d",d);
to
cpp Syntax (Toggle Plain Text)
  1. printf("%s", d.c_str());
Reputation Points: 21
Solved Threads: 22
Junior Poster
ivailosp is offline Offline
129 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Trouble with files
Next Thread in C++ Forum Timeline: change size programatically in cell





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC