std::stoi 的问题未在 MinGW GCC 5.1.0 上声明

Problems with std::stoi, was not declared on MinGW GCC 5.1.0

我在 运行 MinGW GCC 5.1.0 的计算机上尝试了我的代码。

当我输入时:

g++ hope.cpp -o hope -I D:\armadillo-7.600.2\include

cmd 显示:

hope.cpp:183:26: error: 'stoi' was not declared in this scope
Point_Num = stoi(temp[1]);//number of point
                      ^
hope.cpp:190:34: error: 'stof' was not declared in this scope
Point(i, 0) = stof(temp[travel]);

但是当我输入:

g++ hope.cpp -o hope -I D:\armadillo-7.600.2\include -std=c++11

命令显示:

C:\Users\von77\AppData\Local\Temp\ccXdhQzS.o:hope.cpp:(.text$_ZN4arma7op_norm21vec_norm_1_direct_stdIdEET_RKNS_3MatIS2_EE[_ZN4arma7op_norm21vec_norm_1_direct_stdIdEET_RKNS_3MatIS2_EE]+0x7b): undefined reference to `dasum_'
C:\Users\von77\AppData\Local\Temp\ccXdhQzS.o:hope.cpp:(.text$_ZN4arma7op_norm21vec_norm_2_direct_stdIdEET_RKNS_3MatIS2_EE[_ZN4arma7op_norm21vec_norm_2_direct_stdIdEET_RKNS_3MatIS2_EE]+0x7f): undefined reference to `dnrm2_'
C:\Users\von77\AppData\Local\Temp\ccXdhQzS.o:hope.cpp:(.text$_ZN4arma4blas3dotIdEET_yPKS2_S4_[_ZN4arma4blas3dotIdEET_yPKS2_S4_]+0x3f): undefined reference to `ddot_'
C:\Users\von77\AppData\Local\Temp\ccXdhQzS.o:hope.cpp:(.text$_ZN4arma6lapack5gesddIdEEvPcPiS3_PT_S3_S5_S5_S3_S5_S3_S5_S3_S3_S3_[_ZN4arma6lapack5gesddIdEEvPcPiS3_PT_S3_S5_S5_S3_S5_S3_S5_S3_S3_S3_]+0x8c): undefined reference to `dgesdd_'
collect2.exe: error: ld returned 1 exit status

在我使用 atoi 而不是 stoi 之后: 我得到了与 "g++ hope.cpp -o hope -I D:\armadillo-7.600.2\include -std=c++11".

相同的结果

您需要包含字符串 header

#include <string>

并且您需要指定命名空间

std::stoi(temp[1]);