gpt4 book ai didi

c++ - 新的 C++11 range-for (foreach) 语法 : which compilers support it?

转载 作者:可可西里 更新时间:2023-11-01 15:22:09 24 4
gpt4 key购买 nike

我在 this BoostCon presentation by Jeremy Siek 中看到了这个 c++11 代码片段:

deque<int> topo_order;
topological_sort(g, front_inserter(topo_order));

for (int v : topo_order){ //line 39
cout << tasks[v] << endl;
}

尝试在 gcc 中编译时出现以下错误:

main.cpp:39: error: expected initializer before ‘:’ token

这让我想知道,哪些编译器实际上支持这种语法?

最佳答案

好吧,至少 GCC supports it in 4.6 (功能称为“基于范围的”)。如果您已经拥有最新版本,请不要忘记添加 -std=c++0x 选项。

关于c++ - 新的 C++11 range-for (foreach) 语法 : which compilers support it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5032435/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com