Visual Studio 2013 C ++标准库 [英] Visual studio 2013 C++ standard library

查看:128
本文介绍了Visual Studio 2013 C ++标准库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2013在c ++中编写以下代码:

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."

起初我很困惑,但发现搜索后std的最小值/最大值可能有所帮助.但是,尝试编译时出现错误,告诉我名称空间"std"没有成员"min",也没有成员"max".

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."

我做错什么了吗,还是Visual Studio 2013不包括最小/最大?

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

推荐答案

在我看来,您好像忘记了#include <algorithm>.

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

您的代码应如下所示:

#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;
}

这篇关于Visual Studio 2013 C ++标准库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆