stoi and stoll in c++
c++, compilation, string, string.h
Solution
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>`.
Problem
I have #include(string) in my declaratives at the top of the program but when I try to run stoi(string) or stoll(string) i get the following error. I am running Cygwin g++ v4.5.3. Z:\G\CSCE 437>g++ convert.cpp -o conv convert.cpp: In function `void transfer(std::string*)': convert.cpp:103:36: error:`stoll' was not declared in this scope convert.cpp:116:35: error: `stoi' was not declared in this scope ``` fileTime[numRec] = stoll(result[0]); //converts string to Long Long if(numRec = 0){ beginningTime = fileTime[0]; } fileTime[numRec] = timeDiff; hostName[numRec] = result[1]; diskNum[numRec] = stoi(result[2]); type[numRec] = result[3]; offset[numRec] = stoi(result[4]); fileSize[numRec] = stoi(result[5]); responseTime[numRec] = stoi(result[6]);` ``` Where result is an array of strings.