I am currently using Visual Studio Community 2017. Studying the C ++ language standards in the project properties, they provide only C ++ 14 and C ++ 17. Since my code was executed for the previous assignment using the compiler for C ++ 11, I cannot run my code with functions like stoi. My question is, is there a way to add C ++ 11 to the locales for C ++?
I am creating a GUI DLL, my initializations are:
#include <string>
#include "stdafx.h"
using namespace std;
Here I create a fraction class, the main errors follow in ifstream:
istream& operator>>(istream& in, Fraction& f) {
string number;
in >> number;
size_t delimiter = number.find("/");
if (delimiter != string::npos) {
int n = stoi(number.substr(0, delimiter));
int d = stoi(number.substr(delimiter + 1));
if (d == 0) {
throw FractionException("Illegal denominator, cannot divide by zero.");
}
else if (n == 0 && d != 0) {
f.numVal = 0;
f.denVal = 1;
}
else {
f.numVal = n;
f.denVal = d;
f.normalizeAndReduce(f.numVal, f.denVal);
}
}
else {
f.numVal = stoi(number);
f.denVal = 1;
}
return in;
}
I get the following errors:
C2679: binary '>>': no operator found which takes a right-hand operator of type 'std::string"
C3861: 'stoi' identifier not found
This method worked fine in eclipse, not sure what I am doing wrong.
source
share