Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio 2013 C++ standard library [closed]

I am using visual studio 2013 to program the following code in c++:

#include <iostream>

using namespace std; 

int main()
{
    std::cout << "Please enter two integers: " << std::endl;
    int v1 = 0, v2 = 0;
    std::cin >> v1 >> v2; 
    int current = std::min(v1, v2);
    int max = std::max(v1, v2);
    while (current <= max)
    {
        std::cout << current << std::endl;
        ++current;
    }
    return 0;

}

This code was meant to solve: "Write a program that prompts the user for two integers. Print each number in the range specified by those two integers."

I was confused at first, but found that std min/max could help after searching. However, I am getting errors when trying to compile, telling me that namespace "std" has no member "min" and no member "max."

Did I do something wrong, or does Visual Studio 2013 not include min/max?

like image 848
Steve Avatar asked Jul 02 '14 22:07

Steve


People also ask

Is Visual Studio 2013 still supported?

x will continue to be supported until January 2020. For Visual Studio 2015 and Team Foundation Server 2015, RTW is no longer supported. For Visual Studio 2013 and Team Foundation Server 2013, RTW is no longer supported. For Visual Studio 2012 and Team Foundation Server 2012, RTW is no longer supported.

Is C available in Visual Studio?

Microsoft Visual C++ (MSVC) refers to the C++, C, and assembly language development tools and libraries available as part of Visual Studio on Windows.

What version of C++ is in Visual Studio 2013?

Visual Studio 2013 (VC++ 12.0) You can download other versions and languages from Update for Visual C++ 2013 Redistributable Package or from my.visualstudio.com.


1 Answers

It looks to me like you forgot to #include <algorithm>.

Your code should look like this:

#include <iostream>
#include <algorithm> // notice this

using namespace std; 

int main()
{
    std::cout << "Please enter two integers: " << std::endl;
    int v1 = 0, v2 = 0;
    std::cin >> v1 >> v2; 
    int current = std::min(v1, v2);
    int max = std::max(v1, v2);
    while (current <= max)
    {
        std::cout << current << std::endl;
        ++current;
    }
    return 0;
}
like image 156
Jashaszun Avatar answered Sep 30 '22 14:09

Jashaszun