ada*_*ian 2 c++ arrays gcc stl c++11
我想知道在c ++中执行以下代码段的一些替代方法。
int i;
cin >> i;
int arr[i];
Run Code Online (Sandbox Code Playgroud)
我最近开始研究竞争性编程并尝试学习更多。
编辑:对于那些不是cpp的评论。它使用我正在使用的类中正在使用的makefile成功编译,gcc -std=c++11 -o a.exe main.cpp并在输入长度为1时返回到控制台
array length: 1
Run Code Online (Sandbox Code Playgroud)
son*_*yao 11
您应该改用std::vectorC ++,例如
int i;
cin >> i;
std::vector<int> arr(i);
Run Code Online (Sandbox Code Playgroud)
顺便说一句:C ++标准不支持VLA。另请参阅C ++编译器中的可变长度数组(VLA)