Sam
Sam

Reputation: 933

stof function is not declared in this scope c++

When I compile my code,I got this error

'stof' was not declared in this scope.

and my code is

#include<iostream>
#include<string.h>
using namespace std;

int main()
{
string str,str2;
cin>>str>>str2;
float a,b;
a = stof(str);  //error
b = stof(str2); //error
cout<<a+b;
return 0;
}

how to resolve this ??

Upvotes: 1

Views: 15000

Answers (3)

Nobody
Nobody

Reputation: 1

With dev c++ you need to go to Project > Project Options (Ctrl +h) > Compiler > Code generation > Language standard and select GNU C++ 11

(Not too sure about the menu since i have the language set to italian but it's pretty much that)

Upvotes: 0

Bokha
Bokha

Reputation: 121

Also std::stof can only be compiled using c++11 version for which compilation should be done as:

g++ -std=c++11 code.cc

Upvotes: 4

David G
David G

Reputation: 96810

std::stof is located in the standard C++ header <string>.

Upvotes: 3

Related Questions