如何使用C ++ 11 std :: stoi与gcc? [英] How to use C++11 std::stoi with 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屋!