Mar*_*ier 0 c++ algorithm c++11
试图刷新我的C++,我从网络搜索中选择了一个帮助函数,并在查看C++参考之前尝试了它:
int count_vowels(const std::string &input) {
return std::count_if(input.begin(), input.end(), is_vowel);
}
Run Code Online (Sandbox Code Playgroud)
当我查看count_if()的更多细节时,我发现它是<algorithm>库代码(http://www.cplusplus.com/reference/algorithm/count_if/)的一部分,我在编译时没有包含它并运行它.为什么没有<algorithm>标题时函数会工作?我已经包含了<iostream>,<string>(显然)和<sstream <>.-std=c++11如果重要的话,我正在使用编译标志.
此外,如果它在没有<algorithm>标题的情况下工作,为了清楚起见,我是否应该将该标题放入其中(或者因为其他编译器不一定会选择必要的函数定义)?