stoi and stoll in c++

最后都变了- 提交于 2019-12-06 01:16:02

These functions are new in C++11, and GCC only makes it available if you specify that version of the language using the command-line option -std=c++11 (or -std=c++0x on some older versions; I think you'll need that for version 4.5).

If you can't use C++11 for some reason, you could convert using string streams:

#include <sstream>

template <typename T> from_string(std::string const & s) {
    std::stringstream ss(s);
    T result;
    ss >> result;    // TODO handle errors
    return result;
}

or, if you're feeling masochistic, the C functions in such as strtoll declared in <cstring>.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!