Why is the C++ syntax so complicated?

Viewed 16040

I'm a novice at programming although I've been teaching myself Python for about a year and I studied C# some time ago.

This month I started C++ programming courses at my university and I just have to ask; "why is the C++ code so complicated?"

Writing "Hello world." in Python is as simple as "print 'Hello world.'" but in C++ it's:

# include <iostream>
using namespace std;

int main ()
{
    cout << "Hello world.";
    return 0;
}

I know there is probably a good reason for all of this but, why...

  • ... do you have to include the <iostream> everytime? Do you ever not need it?
  • ... same question for the standard library, when do you not need std::*?
  • ... is the "main" part a function? Do you ever call the main function? Why is it an integer? Why does C++ need to have a main function but Python doesn't?
  • ... do you need "std::cout << "? Isn't that needlessly long and complicated compared to Python?
  • ... do you need to return 0 even when you are never going to use it?

This is probably because I'm learning such basic C++ but every program I've made so far looks like this, so I have to retype the same code over and over again. Isn't that redundant? Couldn't the compiler just input this code itself, since it's always the same (i.e. afaik you always include <iostream>, std, int main, return 0)

10 Answers
Related