3

I'm having trouble getting my code to compile. I want to use std::to_string as it is a convenient one liner for converting an int into a string. However, I keep getting " 'to_string' is not a member of 'std' ", so this seems to be a compiler problem as this should be a standard capability in later C++ versions.

The first time it failed to compile, I did some research and based on my findings I tried the following:

Including the following headers:

#include <iostream>
#include <string>
#include <sstream>

Trying to compile in C++ 11, 17, and 20

Changing intellisense mode between msvc-x64 and gcc-x64

Changing intellisense engine between "Default" and "Tag Parser"

None of these seem to rectify the problem. I don't know what else to try. Any insight would be appreciated.

kevinaguy
  • 63
  • 1
  • 3
  • 2
    How are you using [std::to_string()](https://en.cppreference.com/w/cpp/string/basic_string/to_string)? – David C. Rankin Feb 07 '20 at 04:36
  • 3
    Please try to create a [mcve] to show us. And also please copy-paste the *full* and *complete* build output into the question body, and add comments on the line(s) you get the error(s). Also please take some time to read about [how to ask good questions](http://stackoverflow.com/help/how-to-ask), as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). – Some programmer dude Feb 07 '20 at 04:38
  • 1
    There's a similar question with some workarounds and perhaps some possible solutions for you. https://stackoverflow.com/questions/12975341/to-string-is-not-a-member-of-std-says-g-mingw – bcal Feb 07 '20 at 04:48
  • SImilar question [here](https://stackoverflow.com/questions/60047429/centos7-g-to-string-is-not-in-a-member-of-std/60047525#60047525). However, it is related to GCC, not MSVC but it could help you – NutCracker Feb 07 '20 at 06:58
  • VS Code doesn't do great for native Windows C++ stuff, even if you remembered to launch it from a VS Dev Powershell like you're supposed to. I'd recommend using the Remote extensions to code in WSL or a container, or just going full VS Community if you need to be in the Windows world. – sweenish Feb 07 '20 at 13:50
  • Compiles fine: https://gcc.godbolt.org/z/3Ke6x3nd3 – Alexander Dyagilev May 06 '21 at 17:22

1 Answers1

1

Change C++ standard version to C++11 (minimal, by default it's C++98). You may also check Compiler path: it's clang by default.

You can change it in the C/C++ configuration UI by running the command C/C++: Edit Configurations (UI) from the Command Palette (Ctrl+Shift+P).

PiotrB
  • 133
  • 1
  • 10