cylin said:
Dear all,
To do below is too long.
cout << "Name: " << name << ", Age: " << age << endl;
Removing unnecessary whitepace and using
same newline expression in order to form
a valid comparision:
printf("Name: %s, Age: %d\n",name,age);
cout<<"Name: "<<name<<", Age: "<<age<<'\n';
Is an extra four characters really too high
a price to pay for type safety?
Can cout use "%" to implement?
I suppose one could write some code to simulate
it, but what's the point?
Also note that 'printf()' is just as valid
(but less safe) a function in C++ as are the
stream inserters.
If you insist upon using '%' specifiers, why not just
use 'printf()'?
-Mike