In terms of the printf verses cout thing, I’ve been trying to figure that out for 12 years. What I mean is, I can’t understand for the life of me why iostream was ever created, why it continues to exist, and why anyone (everyone but me I guess) uses it. With GNU CodeBlocks optimizing for small size and with debug symbols removed, this…
1 2 3 4 5 6 7 8
|
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
|
Produces a Hello, World! And compiles to 457K. This…
1 2 3 4 5 6 7
|
#include <stdio.h>
int main()
{
printf("Hello world!\n");
return 0;
}
|
Does the same thing and compiles to 6K. That’s 76 times bigger!
The format specifiers tell printf how to interpret the result, i.e., signed number, unsigned number, string, etc. Very useful. When moving on from console programming to GUI programming iostream isn’t much use, but the C Standard Library stdio functions are still much used and very useful.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <stdio.h>
int main()
{
char szBuffer[]="Hello, World!";
printf
(
"%s\t%u\n", //Format Specifier
szBuffer, //Interpret szBuffer as a NULL terminated char string
(unsigned)szBuffer); //Interpret it as an address
return 0;
}
//Output
//Hello, World! 2293554
|
The Windows Api is a beautiful thing for those with an eye for it. I believe it’s a work of genius myself. A thing of unbelievable intellectual elegance and beauty. With the CreateWindow() call you can create a main program window, any standard or common control, a custom control, or an ActiveX control. All this from just varying the parameters of the call. I have never found any other GUI framework for any operating System this elegant. My personal feeling is that class frameworks mutilate it, so I don’t use them. But to each his own.