What wrong with this code?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 9
Reputation: StephanJos has a little shameless behaviour in the past 
Solved Threads: 0
StephanJos StephanJos is offline Offline
Newbie Poster

What wrong with this code?

 
-1
  #1
Oct 24th, 2008
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;
}
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 273
Reputation: Sci@phy will become famous soon enough Sci@phy will become famous soon enough 
Solved Threads: 42
Sci@phy's Avatar
Sci@phy Sci@phy is offline Offline
Posting Whiz in Training

Re: What wrong with this code?

 
0
  #2
Oct 24th, 2008
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!)
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 118
Reputation: chococrack is on a distinguished road 
Solved Threads: 14
chococrack's Avatar
chococrack chococrack is offline Offline
Junior Poster

Re: What wrong with this code?

 
1
  #3
Oct 25th, 2008
Well it's dead obvious... theres a SMILEY FACE IN YOUR CODE! o.0
I would love to change the world, but they won't give me the source code
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 128
Reputation: kenji is an unknown quantity at this point 
Solved Threads: 10
kenji's Avatar
kenji kenji is offline Offline
Junior Poster

Re: What wrong with this code?

 
0
  #4
Oct 25th, 2008
Check your printf you havnt used the correct specifier
And she said "Let there be light" and on the seveth day Windows booted.
And the crowds screamed in terror and cowered in fear for Microsoft had approached.
From the testament of 10011101
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 128
Reputation: kenji is an unknown quantity at this point 
Solved Threads: 10
kenji's Avatar
kenji kenji is offline Offline
Junior Poster

Re: What wrong with this code?

 
0
  #5
Oct 25th, 2008
Check the printf your using the wrong format specifier also use the code tags.
And she said "Let there be light" and on the seveth day Windows booted.
And the crowds screamed in terror and cowered in fear for Microsoft had approached.
From the testament of 10011101
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 129
Reputation: ivailosp is an unknown quantity at this point 
Solved Threads: 22
ivailosp ivailosp is offline Offline
Junior Poster

Re: What wrong with this code?

 
0
  #6
Oct 25th, 2008
change
  1. printf("%d",d);
to
  1. printf("%s", d.c_str());
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC