C: Good Habits re: Transitioning to C++

后端 未结 13 647
梦毁少年i
梦毁少年i 2020-12-13 02:47

I\'ve been learning C at Varsity for just shy of 2months now, and next year we\'ll be moving on to C++.

Are there any habits I should get into with my C programmin

13条回答
  •  余生分开走
    2020-12-13 03:21

    C++ programs are totally different. you had better spend your time learning C++ than working on C elements trying to improve them for C++.

    For example even the simple 'Hello World' program, differs considerably:

    C:

    #include 
    int main(void)
    {
      printf("Hello, world!\n");
      return 0;
    }
    

    C++:

    #include 
    int main()
    {
       std::cout << "Hello, world!\n";
    }
    

    (Examples from here).

    As 'printf' is a function whereas 'cout' is not a function but an instance of an ostream class.

    Further reading: iostream.

提交回复
热议问题