to_string is not a member of std, says g++ (mingw)
This is a known bug under MinGW. Relevant Bugzilla. In the comments section you can get a patch to make it work with MinGW.
This issue has been fixed in MinGW-w64 distros higher than GCC 4.8.0 provided by the MinGW-w64 project. Despite the name, the project provides toolchains for 32-bit along with 64-bit. The Nuwen MinGW distro also solves this issue.
MinGW 4.8.1 can't use C++11
I tested this in my MinGW 4.8.1 installation and, indeed, stoi()
is not recognized, for whatever reason. However, its functionality can be easily replaced using strtol()
, which does work fine in 4.8.1. Of course, the parameter types are somewhat different between the two functions, but the differences can be accounted for trivially. Please see documentation for the two functions.
stoi and stoll in c++
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>
.
Related Topics
Best Bignum Library to Solve Project Euler Problems in C++
Why Is the Copy Constructor Called When We Pass an Object as an Argument by Value to a Method
Adding Signals/Slots (Qobject) to Qgraphicsitem: Performance Hit
Overload Resolution with Std::Function
Speed Difference Between If-Else and Ternary Operator in C...
Best Practices for Recovering from a Segmentation Fault
Why Is the Order of Evaluation for Function Parameters Unspecified in C++
Oracle Oci, Bind Variables, and Queries Like Id in (1, 2, 3)
Sorting a Vector of Objects by a Property of the Object
C++ Function for Picking from a List Where Each Element Has a Distinct Probability
Overloading Operator<< for a Templated Class
How to Save Two Camera's Data But Not Influence Their Picture-Acquire Speed