I had this problem before but found a work around, only this time a work around is not an option.
I'm trying to use the 'stof' function but I'm getting errors saying: 'stof' is not a member of 'std' Function 'stof' could not be resolved
I'm using it in the exact way if shows on this page:http://www.cplusplus.com/reference/string/stof/
And here are my includes:
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
So, what am I doing wrong? And if a solution cannot be found could someone point me to another way to convert string to float and have it throw an exception if the string was not compatible?
EDIT: Updating with sample program and errors.
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
string testString = "";
float testFloat = 0.0;
testFloat = std::stof(testString);
return 0;
}
The errors I get are:
Description Resource Path Location Type 'stof' is not a member of 'std' main.cpp /Assignment/src line 33 C/C++ Problem
Description Resource Path Location Type Function 'stof' could not be resolved main.cpp /Assignment/src line 33 Semantic Error
stof is a C++11 function. Make sure your compiler supports it (no compiler has full support for C++11 yet, though most modern compilers out there right now support a fairly large subset).
On g++ for instance you have to enable it with the -std=c++11
option (std=c++0x
pre g++-4.7).
If you're using g++, please check which version you're using with g++ -v
- if it's an old version (like 4.2 for instance) c++11 functionality won't be available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With