C ++在初始化程序中指定数组索引,例如C [英] C++ specify array indexes in initializer, like C
问题描述
我以前使用过C(嵌入式的东西),我可以像这样初始化我的数组:
I used C before (embedded stuff), and I can initialize my arrays like that:
int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };
即我可以在初始化器中指定索引.目前,我正在学习 Qt/C ++
,我不敢相信C ++不支持此功能.
i.e. I can specify indexes inside initializer.
Currently I'm learning Qt/C++
, and I can't believe this isn't supported in C++.
我有这个选项: -std = gnu ++ 0x
,但是无论如何它不被支持.(我不知道C ++ 11是否支持它,因为Qt在gcc 4.7.x上无法正常工作)
I have this option: -std=gnu++0x
, but anyway it isn't supported. (I don't know if it is supported in C++11, because Qt works buggy with gcc 4.7.x)
那么,C ++真的不支持它吗?也许有办法启用它?
So, is it really not supported in C++? Or maybe there's a way to enable it?
UPD:当前我要初始化const数组,因此 std :: fill
无法正常工作.
UPD: currently I want to initialize const array, so std::fill
won't work.
推荐答案
几年后,我偶然地对其进行了测试,并且可以确认它可以在 g ++ -std = c ++ 11
中使用,g ++版本为4.8.2.
After years, I tested it just by chance, and I can confirm that it works in g++ -std=c++11
, g++ version is 4.8.2.
这篇关于C ++在初始化程序中指定数组索引,例如C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!