警告:扩展初始值设定项列表仅适用于-std=c++0x或-std=gnu++0x
Warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x
我试图声明一个矩阵,当我编译时,我得到了这个:
extended initializer lists only available with -std=c++0x or -std=gnu++0x
当尝试另一种解决方案时,我得到了这个:
ISO C++ forbids variable length array 'A' (line 16)
这是我最后一次尝试的代码:
#include<iostream>
#include<cmath>
#include<fstream>
#include<cstdlib>
using namespace std;
int main()
{
int m, l;
ifstream MatrixA ("A.txt");
MatrixA >> m;
MatrixA >> l;
int A [m][l];
for (int lineA = 0; lineA <= m; lineA++)
{
for (int colA = 0; colA <= l; colA++)
{
A [lineA][colA];
}
}
cout << "Matrix A: " << A[m][l] << endl;
return 0;
}
C++不支持可变大小的内置数组。如果您需要可变大小的数组维度,则需要使用动态执行必要内存分配的东西。一个相对直接的替代方案是使用std::vector
s:的std::vector
std::vector<std::vector<int> > A(m, std::vector<int>(l));
相关文章:
- 为什么 std::erase(std::erase_if) 不是适用于<algorithm>任何容器的模板?
- 使输出流式处理运算符适用于 boost::variant<std::vector<int>、int、double 的正确方法是什么>
- 结构化绑定是否适用于 std::vector?
- 没有适用于 std::unique_ptr 的适当默认构造函数
- 适用于 std::unique_ptr 的内存高效自定义删除器?
- std::string 是否仅适用于 c++ 中的'std::cin'
- 为什么不区分大小写适用于 std::unordered_set的 std::hash 函数?
- 为什么我的"choose k from n"算法适用于 std::vector,而不适用于 std::map?
- 无法获得 boost::spirit parser&lexer 适用于 std::string 或 int 或 double 以外的令牌类型
- 重载分辨率如何适用于 std::vector:<int>:insert
- 如何将上下文信息传递给自定义运算符<<适用于 std::iostream
- 在C++std::streams中,失败后,如何获得失败原因?必需:线程安全,适用于Windows和Linux(或至少M
- 适用于 MacOS 的"-std=gnu++0x"选项
- 警告:扩展初始值设定项列表仅适用于-std=c++0x或-std=gnu++0x
- 警告:扩展初始化器列表仅适用于STD c++ 11
- 自定义迭代器适用于std::sort,但不适用于tbb::parallel_sort
- 不在异常中嵌入std::字符串的规则是否仍然适用于move构造函数
- boost::variant是否适用于std::string
- 如何包装对"std::thread"构造函数的调用?(适用于gcc、VS和icpc)
- 可变参数模板转换为 std::function<R(ARGS...)>适用于 GCC 而不是 MSVC2013,为什么?