[英]'for_each_n' is not a member of 'std' in C++17
我有一小段用于std::for_each_n
循环的代码。 我尝试使用以下命令在内置Coliru编译器 GCC C++17 上运行它:
g++ -std=c++1z -O2 -Wall -pedantic -pthread main.cpp && ./a.out
但是编译器给出了一个错误, “'for_each_n' 不是 'std' 的成员”。
我的代码如下,是从cppreference复制的。
#include <algorithm>
#include <iostream>
#include <vector>
int main()
{
std::vector<int> ns{1, 2, 3, 4, 5};
for (auto n: ns) std::cout << n << ", ";
std::cout << '\n';
std::for_each_n(ns.begin(), 3, [](auto& n){ n *= 2; });
for (auto n: ns) std::cout << n << ", ";
std::cout << '\n';
}
那么,为什么我会收到错误消息?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.