I'm reading a book on C++ and it's using "cout" to print to the screen (i'm coming from vb of course)... but i've seen the statement "printf" to do the same thing. what's the difference between these?
Printable View
I'm reading a book on C++ and it's using "cout" to print to the screen (i'm coming from vb of course)... but i've seen the statement "printf" to do the same thing. what's the difference between these?
Well, cout is the C++ way of console screen dumping. printf is the old ANSI C way of printing to the screen.
For console applications, stick with cout unless your learning C.
cout is a defined member of an 'ostream', which are type safe at compile time, and you can define your own actions. They're also simpler:
if you have your own class, then you can make it define something so that you can put it into the stream, and it will display as you want it to.Code:printf("%s = %d\n", mychar, mynumber);
cout << mychar << " = " << mynumber << endl;