How to write portable code in c++?

后端 未结 12 2005
情话喂你
情话喂你 2020-11-30 03:47

What are the things that I should keep in mind to write portable code? Since I\'m a c++ beginner, I want to practice it since beginning.

Thanks.

12条回答
  •  情话喂你
    2020-11-30 04:25

    Use STL types when possible. Be careful of using system dependent types and APIs. For example don't use types like UINT, and DWORD on Windows.

    You can use a library like boost to make it easier for you to write portable code. If you need a GUI consider using a cross platform toolkit like Qt.

    Sometimes you will need to write platform specific code, and in those cases you can do something like this:

    #ifdef _WIN32
    #include 
    #else
    #include 
    #endif
    

提交回复
热议问题