我正在使用Visual Studio 2013来编写以下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;
}
这段代码旨在解决以下问题:“编写一个程序,提示用户输入两个整数。打印出由这两个整数指定范围内的每个数字。”
一开始我很困惑,但在搜索后发现std min/max可以帮助解决问题。然而,在尝试编译时我得到了错误,告诉我命名空间“std”没有成员“min”和“max”。
我做错了什么吗?还是Visual Studio 2013不包含min/max?
template< class T > constexpr const T& min( const T& a, const T& b ); template< class T, class Compare > constexpr const T& min( const T& a, const T& b, Compare comp );
参数:#include <algorithm>
即可。 - Daniel Kleinstein<algorithm>
中”。 - Ben Voigt