When do you not use #include <iostream>, using namescape std and int main()?

I've been programming for a week now and I've always used #include <iostream>, using namescape std, and int main(). so when do you not use them? in what instances and why?
You always need main(). That is where your program begins.

You never need using namespace std;. Only student programs begin that way. It's used so you can say:
 
cout << "hello world" << endl;

rather than having to say:
 
std::cout << "hello world" << std::endl;

Earlier versions of C++ did not have namespaces, so we got used to seeing the shorter form. When they were introduced, the code seemed verbose, so the using namespace thing was introduced to make the code look like it used to.

iostream declares cout, cin, cerr. If you use them, you have to declare them.
You don't use int main when you work on WinAPI applications. When you work on those, you'll type int WINAPI WinMain()

iostream is the input/output stream, do you plan to have input/output? I assume you would.

using namespace std; is only used by students taking an intro class it seems to me from looking at a lot of student posts. You don't need using namespace std; It might save you 5 minutes of work now, but later on when you create your own namespaces, using namespace std; becomes gay, and shouldn't really be used.
> Earlier versions of C++ did not have namespaces(...) When they were introduced,
> the code seemed verbose, so the using namespace thing was introduced
I prefer to think that it was a quickfix for all the code that become broken.


> iostream is the input/output stream, do you plan to have input/output?
> I assume you would.
there are other ways to get i/o, by instance, files
you may also create a GUI
Topic archived. No new replies allowed.