gpt4 book ai didi

C++ 无法解析标识符 to_string

转载 作者:行者123 更新时间:2023-11-30 03:35:39 26 4
gpt4 key购买 nike

美好的一天

我找遍了高处和低处,但没有解决方案。

IDE:NetBeans IDE 8.2MinGW:使用“最新的”MinGW 编译器。

原始问题:

我想将一个整数转换为字符串。

使用 this方法,我试图转换为字符串,但是

这个提议的方法 std::to_string() 在使用时导致错误(以 to_string 作为错误)

unable to resolve identifier to_string

项目依赖:

#include <string>
#include <iostream>

在搜索此问题的解决方案时,出现了 2 个突出的解决方案 herehere

设置 C 和 C++ 编译器版本应该可以解决这个问题。

没有,有什么建议吗?

最小代码:

#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 的已知问题

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

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

编译无误

如果您想在 Netbeans 中更改工具链,您必须在项目属性中添加新的工具集合。

关于C++ 无法解析标识符 to_string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41164774/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com