-std=c++11 Error while compiling

Hello,

Could you please refer to the code below and guide me as to how that error could be resolved?


///Listing 2-1
///A program that checks that the number the user input fits within a C++ integer variable

#include <iostream>
#include <limits>

using namespace std;

int main()
{
int min{ std::numeric_limits<int>::max() }; //<-error
int max{ std::numeric_limits<int>::min() }; //in min{} and the min function in max{}

bool any(false); //Variable initializations
int x;

while (std::cin >> x ) //This loop executes with input provided by the user
{
any = true;
if (x<min) //Evaluates user input against min value integers can have
min = x;

if (x)
max = x;
}

if (any) //This will execute if the user entered something
std::cout << "min = " << min << "\nmax = " << max << '\n'; //This will print the min value
} //and the max value on a new line
There is no error.

LLVM: http://coliru.stacked-crooked.com/a/115be09fb1072c88
Microsoft: http://rextester.com/FCIS60602

It appears that you are using an outdated compiler; update to a newer version.

Temporary fix (old compiler):
1
2
3
4
5
// Lines 11, 12
// int min{ std::numeric_limits<int>::max() };    //<-error
int min = std::numeric_limits<int>::max() ; 
// int max{ std::numeric_limits<int>::min() };	//in min{} and the min function in max{}
int max = std::numeric_limits<int>::min() ;


Consider declaring min and max as const objects. const int min = ...
Last edited on
Consider declaring min and max as const objects. const int min = ...

The variables are modified later in the code so making them constants is probably not the right thing to do here.
I stand corrected. Thank you, Peter87.
Topic archived. No new replies allowed.