Discuss c++ cross platform coding in detail
- 2020-05-27 06:44:40
- OfStack
Recently, a project under windows will be placed on raspberry pie to make full use of bandwidth resources and make it work day after day
Code the problem and scheme in this record 1
Under windows, vs2015 is now used. The default code of the code file created is ANSI,windows's unique concept, local code, and gb232 in combination with the actual situation
When debugging vs, it is convenient to check the ANSI encoding and unicode encoding
In the code
The ANSI encoded string is denoted by "hello,world"
L"hello, world "stands for unicode encoded string
These two expressions are not affected by the way the code file itself is encoded
For linux programming, the default encoding of the code file is utf8
In the code
Take the string "hello,world" and encode it according to the encoding of this file
For L"hello, the world ", I have not tested
For source files with no non-ancii encoded characters in the code, ANSI and utf8 are fine
However, if there is Chinese, there are various problems. For the above features, the following solutions are adopted
The source code file is encoded in 1utf8, and there is one plug-in available for vs, ForceUTF8
The constant string in the code is L"hello, world "unicode encoding
For various interface parameters and return values, try to write unicode
For printouts, try to encode utf8
Meanwhile, for the convenience of operation, utf8 and unicode operation macros are provided to facilitate the string encoding conversion of utf8 and unicode