-
As a general rule, if you're going to ever do a serious project, I'd advise to never use the 'using' keyword. Use std::cout, std::string, etc. instead. It's better form, and in the end it makes code more readable, especially when you're working with functions from many different namespaces.
I know on the basic things that beginners do, "using namespace std" works fine, but I feel it sets people up for bad habits later on. It effectively removes the entire benefit that namespaces provide. So my advice is, rather than starting with "using" and later unlearning it, start off where you'll end up.
This is how I'd code that:
Code:
#include <iostream>
int main()
{
char x;
std::cout << "Type c and press enter" << std::endl;
std::cin >> x;
}
It's not truly necessary to return 0; after main(), because a return 0; is implicit if there's no other return statement.
Adding std::endl will add a line break after the text.
Any text/website recommending iostream.h is extremely outdated C++, iostream is the new header, and has been for many years now. That would be a good sign to move on to a better tutorial.
-
I believe it's because the libstd++ streams library in MinGW (the compiler Dev-C++ uses) consist of large heirachies of inherited classes, all linking to static libraries; the MinGW gcc compiler is very conservative about removing seemingly unneeded code IIRC. If you want a small executable you can
1) build on Linux
2) use Cgywin DLLs and reduce your program's portability a cinch
3) use some other compiler (you can still use them from within Dev-C++ if you fiddle around with the settings a bit)
4) use <stdio.h> and the C functions
5) write your own tiny "pocket-size" streams library (yeah, I've done it before)
You can also disable debugging symbols and enable executable stripping... check in Tools -> Compiler Options -> Settings.