'for each'不是 std 的成员。 已启用 C++11 支持
'for each' is not a member of std. C++11 support already enabled
教授的家庭作业代码如下:这是直接开箱即用的,我没有修改我教授的代码。程序还有更多内容,但这就是错误发生的地方。黑体显示的问题行
std::cout << "nAll remaining courses with enrollments:n";
allCourses = WSUCourse::getAllCourses();
std::for_each(
allCourses.begin(),
allCourses.end(),
WSUCoursePrinter());
我收到以下错误。
g++ -c -g -std=c++11 -MMD -MP -MF "build/Debug/Cygwin_4.x-Windows/main.o.d" -o build/Debug/Cygwin_4.x-Windows/main.o main.cpp
main.cpp: In member function 'void WSUStudentPrinter::operator()(const WSUStudent*)':
main.cpp:26:20: error: 'to_string' is not a member of 'std'
std::cout << std::to_string(studentPtr->getUniqueID()) <<
^
main.cpp: In function 'void test()':
main.cpp:162:4: error: 'for_each' is not a member of 'std'
std::for_each(
^
main.cpp:174:4: error: 'for_each' is not a member of 'std'
std::for_each(
^
nbproject/Makefile-Debug.mk:84: recipe for target 'build/Debug/Cygwin_4.x-Windows/main.o' failed
总结一下,它和标题完全一样。"'For each' is not a member of std"
我已经在所有编译它的IDE中启用了对标准11的支持。在代码块上,我把参数放在编译器设置中,在netbeans中,我在编译器的项目属性下改变了它,即使是学校网络上的linux系统也不会运行它,有同样的错误,我使用了标准的11包含行。
关于如何解决这个问题的想法,有人吗?
从评论中确认后:
你忘了包括#include<algorithm>
。包括所需的头文件,使符号foreach
包含在std
名称空间中,从而在程序的其余部分可见。
你的解决方案是纯粹的c++ 98,一个可能的c++ 11解决方案看起来像这样:
std::cout << "nAll remaining courses with enrollments:n";
for (auto & course : WSUCourse::getAllCourses())
{
//whatever WSUCoursePrinter does.
course.print() ;
}
我更喜欢这种方式,它不需要算法头。
相关文章:
- 编译时未启用intel oneApi CUDA支持
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 使用CMake检测支持的C++标准
- 为什么istream不支持右值提取
- 可以在 macOS 上启用的最低支持的 SSE 标志是什么?
- OpenCV 4.x+ 需要启用 C++11 支持编译暗网致命错误
- 我有一个启用了代理存根支持的 ATL 项目,在哪里可以找到 xdlldata.h 文件中所有方法的实现
- 请求C 17的编译器通过使用-STD 17标志在-STD = C 17时,将启用STD ::变体的支持
- 如何在 Eclipse 中启用 C++11 支持
- 如何在代码块中启用C 17支持
- 从源代码构建Qt静态,启用OpenSSL支持
- /MP 在 VS2012 中未启用 OpenMP 支持
- __transaction_atomic,但未启用事务内存支持
- 检查我的互联网提供商是否支持并在我的操作系统中以编程方式启用IPv6/Teredo
- 如何在GCC中启用反斜杠支持?
- 在类上启用std::get支持
- 通过cmake在VS 2013中启用c++ 11支持
- Android上启用c++ 11支持
- 在XCode 4.6中启用OpenMP支持
- 'for each'不是 std 的成员。 已启用 C++11 支持