PDA

Click to See Complete Forum and Search --> : Simple, but I'm a beginner


Master
Jun 23rd, 2000, 04:48 AM
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?

PhilipG
Jun 23rd, 2000, 05:16 AM
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.

parksie
Jun 23rd, 2000, 05:45 PM
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:


printf("%s = %d\n", mychar, mynumber);

cout << mychar << " = " << mynumber << endl;


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.