范围 对于循环帮助:令牌之前的预期初始值设定项":"
Range For loop help: Expected initializer before ":" token
我是一个c++新手,我现在正在学习c++入门书。
我写了一个关于字符串的小例子,下面是代码:
#include <iostream>
#include <string>
#include <cctype>
using std::cin;
using std::cout;
using std::endl;
using std::string;
int main() {
string s("Hello World");
for (auto &c : s)
c = toupper(c);
cout << s << endl;
return 0;
}
我在Linux上使用GCC版本4.4.6,我试图用:
编译这段代码:g++ test_strings.c -std=c++0x
,但得到以下错误:
test_strings.c: In function 'int main()':
test_strings.c:14: error: expected initializer before ':' token
test_strings.c:19: error: expected primary-expression before 'return'
test_strings.c:19: error: expected ')' before 'return'
我从教科书中复制了程序,所以我认为这是一个拼写错误,但经过检查并尝试在网上搜索并更新我的gcc后,错误提醒。非常感谢您的帮助。
根据GCC中的c++ 0x/c++ 11支持页面,您需要运行GCC 4.6才能获得range-for功能。
4.6更改页面包含:
改进了对即将到来的c++ 0x ISO c++标准的实验支持,包括对constexpr(感谢Gabriel Dos Reis和Jason Merrill)、nullptr(感谢Magnus Fromreide)、noexcept、无限制联合、基于范围的for循环(感谢Rodrigo Rivas Costa)、不透明enum声明(也感谢Rodrigo)、隐式删除函数和隐式move构造函数的支持。
相关文章:
- 有没有办法重复循环循环?
- 相同的 for 循环适用于其他项目,但不适用于此项目。为什么?
- 将函数应用于特征矩阵中的所有元素,而无需循环
- C++参数类型以接受适用于基于范围的 for 循环的所有序列
- 虽然第三次循环循环,尽管在我眼中没有满足它的条件,因此打印了一个空字符串
- 为什么 OpenCL 嵌套循环仅适用于某些元素
- 避免以不同的迭代剂的循环循环避免几乎相同的代码重复
- 循环循环保存到数组,然后访问;
- 对于循环循环仅 3 次
- 处理媒体循环循环循环通过向量中的对象的各个方面
- 将C转换为循环循环循环
- Openmp-嵌套用于循环
- 有类似于循环(圆形)迭代器的东西吗?
- 关于如何正确循环循环并找到最小的价值,需要基本C 的帮助
- 我如何循环循环switch语句检查重新检查char?(C )
- 我是否必须求助于循环,以比较C 中的两个2D阵列
- 在嵌套循环/循环不变量中检查一次
- 对于作用于整数向量的循环行为异常
- "继续"使用标志作用于哪个循环?
- 为什么在这种情况下PPL明显慢于顺序循环和OpenMP