Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Visual Studio 2017 shows me error, when I use std::wstring?

I just want to use std::wstring in my code just for learning purposes, but when i run this code (below) using Visual Studio 2017, it showns me error (below the code).

code:

#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;
}

error:

Error   C2039   'wstring': is not a member of 'std'
like image 509
Guga Nemsitsveridze Avatar asked May 31 '26 17:05

Guga Nemsitsveridze


1 Answers

You are using a pre-compiled header "pch.h".

The header "pch.h" should be included before all other header files.

If the precompiled header file is "pch.h" and the compile option is /Yu, Visual Studio will not compile anything before the #include "pch.h" in the source file; it assumes all code in the source up to and including that line is already compiled.

So you just have to change the order of inclusion of the header files such that "pch.h" is the first header to be included.

like image 139
P.W Avatar answered Jun 03 '26 06:06

P.W