当我使用std :: wstring时,为什么Visual Studio 2017向我显示错误?

Gug*_*dze 2 c++ std visual-studio-2017

我只是想std::wstring在我的代码中使用,仅出于学习目的,但是当我使用Visual Studio 2017运行此代码(如下)时,它向我显示错误(代码下方)。

码:

#include<string>
#include<iostream>
#include "pch.h"

int main() {
    double f = 23.32;
    std::wstring f_str = std::to_wstring(f);
    std::wcout << f_str;
}
Run Code Online (Sandbox Code Playgroud)

错误:

Error   C2039   'wstring': is not a member of 'std'
Run Code Online (Sandbox Code Playgroud)

P.W*_*P.W 8

您正在使用预编译的标头"pch.h"

该标头"pch.h"应包括在所有其他标头文件之前。

如果预编译的头文件为"pch.h",并且compile选项为/Yu,则Visual Studio不会#include "pch.h"在源文件中的之前编译任何内容;否则,不进行任何编译。它假定源中直至该行(包括该行)的所有代码均已编译。

因此,您只需要更改头文件的包含顺序即可,这"pch.h"是要包含的第一个头。