好吧,我是 C++ 的新手(从 VB 转移过来),我似乎无法弄清楚如何在不执行以下操作的情况下填充数组:
array[0] = 1
array[1] = 2
等等等等
正如所料,我试过这个:
float posVector[3]; //Declared outside of int main() as needs to be global
posVector = {0.0f,0.0f,0.0f}; //Inside int main()
导致显示此错误的原因:
extended initializer lists only available with -std=c++0x or -std=gnu++0x [enabled by default]
到目前为止,我在网上找到的任何东西都没有任何帮助。因此,如果您能给我任何解决此问题的建议,我们将不胜感激!
最佳答案
一旦声明了数组,就不能使用初始化列表对其进行初始化。你可以去
float posVector[] = {0.0f,0.0f,0.0f};
或者更好的选择 std::vector :
#include <vector>
std::vector<float> posVector = {0.0f,0.0f,0.0f};
关于c++ - 无法初始化数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32853565/