C ++无法解析标识符to_string

C ++无法解析标识符to_string

问题描述:

美好的一天

我搜索过高低,但没有解决办法.

I have searched high and low, yet no solution.

IDE: NetBeans IDE 8.2 MinGW::使用最新的" MinGW编译器.

IDE: NetBeans IDE 8.2 MinGW: Using the "latest" MinGW compiler.

原始问题:

我想将int转换为字符串.

I would like to convert an int to string.

我尝试使用方法转换为字符串

Using this method, I attempted to convert to string, however

此建议的方法std::to_string()在使用时导致错误(以to_string为错误)

this proposed method std::to_string() results in the error when used(with the to_string as the error)

无法将标识符解析为"_string"

unable to resolve identifier to_string

项目依赖性:

#include <string>
#include <iostream>

在寻找此问题的解决方案时,出现了2种常见的解决方案此处

Searching for a solution to this issue, 2 promonent solutions appeared here and here

设置C和C ++编译器版本应该可以解决此问题.

Setting the C and C++ compiler versions should apparenlty solve this issue.

没有,有什么建议吗?

最小代码:

#include <string>

struct User_VPN_Info{
    std::string name, expire;
    int DaysLeft;

    User_VPN_Info(){}

    User_VPN_Info(std::string _name, std::string _expire, int _DaysLeft){
        name = _name;
        expire = _expire;
        DaysLeft = _DaysLeft;
    }

    std::string getString(){
        return(name + " + " + expire + " + " + std::to_string(DaysLeft) + " ; ");                                                    
    }                                             //^_______^ problem here
};

MinGW的已知问题

It is know issue with MinGW

gcc  -std=gnu++14 -Wall -Wextra  main.cpp
main.cpp: In function 'int main()':
main.cpp:24:26: error: 'to_string' was not declared in this scope
     cout<<to_string(a)<<endl;

gcc  --version

gcc.exe (GCC) 5.3.0

对于标准" MinGw,应立即使用MinGW-w64-适用于32位和64位Windows

Instant of 'standard" MinGw you should use MinGW-w64 - for 32 and 64 bit Windows

/mingw-w64/i686-6.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin
./g++   -std=c++14   main.cpp

编译没有错误

如果要更改Netbeans中的工具链,则必须在项目属性中添加新的工具集.

If you want change toolchain in Netbeans you have to add new Tool Collection in project properties.