c++ - Visual Studio 中的字符集是什么?

标签 c++

这个问题在这里已经有了答案:





Visual Studio Character Sets 'Not set' vs 'Multi byte character set'

(2 个回答)


8 年前关闭。




这可能是一个基本问题,但由于某些原因我不太明白。

问题是:"Character Set"究竟是什么? Visual Studio 中的属性是?
(例如,您可以设置为: Use Unicode Character SetUse Multi-Byte Character SetNot Set - 在属性中)

我或多或少知道什么是 Unicode,但为什么我们需要设置这个属性?

例如,如果我不设置它并使用 L"hello"项目中的字符串类型,它没有意义吗?

最佳答案

设置 Character Set Visual Studio 中的选项将为您定义一些预处理器符号:

  • Unicode将定义 _UNICODE
  • Use Multi-byte Character Set将定义 _MBCS
  • Not Set不会定义任何这些。

  • 现在,如果你查看 SDK 中的一些头文件,你会看到一堆这样的:
    #ifdef _UNICODE
    #define GetDeltaInfo                        GetDeltaInfoW
    #else
    #define GetDeltaInfo                        GetDeltaInfoA
    #endif /* _UNICODE */
    

    其中 W 和 A 函数是:
    BOOL
    WINAPI
    GetDeltaInfoA(
        __in LPCSTR lpDeltaName,
        __out LPDELTA_HEADER_INFO lpHeaderInfo
        );
    
    /**
     * Gets header information for a delta accessed by Unicode file name.
     * @param lpDeltaName   Delta file name, Unicode.
     * @param lpHeaderInfo  Header information for given Delta.
     * @return              TRUE if success, FALSE otherwise.
     */
    BOOL
    WINAPI
    GetDeltaInfoW(
        __in LPCWSTR lpDeltaName,
        __out LPDELTA_HEADER_INFO lpHeaderInfo
        );
    

    因此,通过设置 Unicode 或多字节,您将选择正确的函数集。

    关于c++ - Visual Studio 中的字符集是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18959551/

    相关文章:

    c++ - 解析格式化输入时划分单词的问题

    java - glTranslate 和 glRotate 没有按预期工作

    c++ - Visual C++ 和超长字符串

    c++ - 使用Lamda从QWebEngineView中的QWebEnginePage获取HTML

    c++ - 单例方法之间的区别

    c++ - WIndows 上的 DLL 中未使用 Breakpad 异常处理程序?

    c++ - 使用 std::enable_shared_from_this 时析构函数崩溃

    c++ - 用作初始值设定项的错误数组,我不知道错误

    c++ - 标准容器的复杂性保证是什么?

    c++ - 关于多态性应该了解的 C++ 知识有哪些