如何使用C ++ 11 std :: stoi与gcc? [英] How to use C++11 std::stoi with gcc?

查看:627
本文介绍了如何使用C ++ 11 std :: stoi与gcc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:


$ b $

b


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

  performer.cpp:错误:'std :: string'没有名为'stoi'的成员

MinGW 和一个更多,以 Eclipse CDT ,他们有他们的答案。但是我使用Linux,为什么它不在这里工作?

解决方案

  #include< iostream> 
#include< string>

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

  #include< iostream> 
#include< string>

使用命名空间std

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

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


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

I am using Qt Creator 2.5.0 and gcc 4.7 (Debian 4.7.2-4). I added "QMAKE_CXXFLAGS += -std=c++11" to .pro file. Everything seems to be OK, I used C++11 std::for_each and so on. But when I included "string" header and wanted to use stoi, i got the following error:

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

I found some questions related to MinGW and one more, to Eclipse CDT and they had their answers. But I use Linux, why it is NOT working here?

解决方案

#include <iostream>
#include <string>

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

or

#include <iostream>
#include <string>

using namespace std    

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

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

这篇关于如何使用C ++ 11 std :: stoi与gcc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆