I am willing to bet you are getting an error at the line below that, when you try to use printf to print a string object to the screen
Oh, you say right, .... and I'm say right too. Because, It's very funny and I don't know why. I will explain, now:
first code:
Code:
#include<iostream>
#include<string>
#include<stdio.h>
#include<sstream>
using namespace std;
int main(){
int number=567;
string myphrase;
stringstream ss(stringstream::in | stringstream::out);
ss<<number;
myphrase = "your number is " + ss.str();
}
this code is NO ERROR.
and this is my second code:
Code:
#include<iostream>
#include<string>
#include<stdio.h>
#include<sstream>
using namespace std;
int main(){
int number=567;
string myphrase;
stringstream ss(stringstream::in | stringstream::out);
ss<<number;
myphrase = "your number is " + ss.str();//--> I use debugger and see that error from this line, mean it's not run line "printf" yet.
/* ************************** */
printf("%s\n",str);
}
So, I don't know how your compiler is, I'm using Code::Block, and I cannot answer why
2) and answer to your question, why I prefer printf/scanf than cint/cout because printf/scanf run faster than cint/cout. It's pretty sure because:
a) my teacher say that
b) many document say that,too
c) my experience: there a problem on SPOJ, I must read N^2 element (N=10^9), if I use printf/scanf I will pass my test, and if I use cint/cout, It's not
that why, I always try to use old function from C
so, who can answer for me above questions, please.
thanks for ton