关于网友提出的“ 不包含algorithm头文件也能使用count函数”问题疑问,本网通过在网上对“ 不包含algorithm头文件也能使用count函数”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 不包含algorithm头文件也能使用count函数描述:
algorithm头文件
如题,C++Primer第五版英文版P378的Exercise10.1说algorithm定义了count函数
但是我没包含这个头文件也照样能用count函数
#include
#include
using std::vector;
int main()
{
vectoriv = { 1, 0, 9, 2, 3, 8, 5, 7, 3, 8, 9, 4, 5, 8, 9, 3, 4, 7, 5, 8, 9, 0, 7, 3, 0, 4, 5, 9, 3, 8, 9, 4, 5, 7, 0, 3, 8, 4, 9, 2, 7, 5 };
std::cout << "The number of value 5: " << std::count(iv.begin(), iv.end(), 5) << std::endl;
return 0;
}
解决方案1:
我运气不好,点不开“这里”

应该是std名字空间已经有了count的声明了吧。
解决方案3:http://ideone.com/JtDbli 解决方案4:
那你运气比较好,看看这里
间接包含了呗