Visual Studio VS 2022.为什么我的智能在使用C++ 20模块时不起作用?

jjhzyzn0  于 2023-01-17  发布在  其他
关注(0)|答案(1)|浏览(258)

我想在VS 2022中使用C++ 20模块。不幸的是,我不能使用智能,即使是在一个非常简单的测试中。我把选项设置为“C最新”,“模块”,高级〉〉“编译为C模块代码”。不幸的是,文件开头有花体字,没有智能,没有标识符突出显示。而且,我们不能再使用import std;(也不能使用std.core)。

//Test of modules.
#define MODULES
#ifdef MODULES
    import module1;
#else
    #include <iostream>
    #include <vector>
    #include <format>
#endif

std::vector<std::string> vec{"Some", " sentence", " to", " print !"};

int main()
{
    std::cout << std::format("Hello World!\n");
    for (auto & str : vec) {
        std::cout << std::format("{}", str);
    }
return 0;
}

文件module1.ixx:

export module module1;

export import <iostream>;
export import <format>;
export import <string>;
export import <vector>;
export import <deque>;
export import <chrono>;

有没有人能告诉我我错过了什么?VS和Intellisence与X11M1N1X完美配合,没有任何问题。

l5tcr1uw

l5tcr1uw1#

智能模块支持仍处于试验阶段。
我在Visual Studio 2022版本17.4.3中测试了您的代码,没有任何问题。
但是,Visual Studio 2022版本17.5.0预览版2.0显示了几条波浪线。
ISO委员会(C++23)投票支持import std;import std.compat;
要在预览版(17.5.0)中使用import std;,您需要添加std.ixx文件。在我的计算机中,该文件位于C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.35.32124\modules中。
从解决方案资源管理器(Add -〉existing Item...)添加文件。
请访问此网站了解更多信息。https://learn.microsoft.com/en-us/cpp/cpp/tutorial-import-stl-named-module?view=msvc-170

相关问题