c++ - 如何将 C++11 std::stoi 与 gcc 一起使用?

标签 c++ gcc c++11 qt-creator

<分区>

Possible Duplicate:
How to convert a number to string and vice versa in C++

我正在使用 Qt Creator 2.5.0 和 gcc 4.7 (Debian 4.7.2-4)。我在 .pro 文件中添加了“QMAKE_CXXFLAGS += -std=c++11”。一切似乎都很好,我使用了 C++11 std::for_each 等等。但是当我包含“string” header 并想使用 stoi 时,出现以下错误:

performer.cpp:336: error: 'std::string' has no member named 'stoi'

我发现了一些与 MinGW 相关的问题和一个more , 至 Eclipse CDT他们得到了答案。但是我使用 Linux,为什么它在这里不起作用?

最佳答案

#include <iostream>
#include <string>

int main()
{
    std::string test = "45";
    int myint = stoi(test);
    std::cout << myint << '\n';
}

#include <iostream>
#include <string>

using namespace std    

int main()
{
    string test = "45";
    int myint = stoi(test);
    cout << myint << '\n';
}

http://en.cppreference.com/w/cpp/string/basic_string/stol

关于c++ - 如何将 C++11 std::stoi 与 gcc 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13589947/

相关文章:

c++ 抛出 'std::length_error' 的实例

c++ - Assimp 计算骨骼

c++ - g++: 错误: 无法识别的选项 ‘--as-needed’

c++ - 设计问题 - 从数据库加载信息

android - arm-gcc编译器编译的c代码的头文件

c - gcc 优化、const 静态对象和限制

c++ - 我们可以在 C++ 中将 stat 与文件的相对路径一起使用吗

c - 功能和性能的返回值

c++ - 错误 : expected primary-expression before ‘(’ token

C++ lambda 按值捕获,无需提前声明变量