#include<string.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstddef>
#include<ctime>
using namespace std;
int main() {
const int sz = 10;
vector<int> ivec;
srand((unsigned)time(NULL));
for (int i = 0; i != sz; i++)
{
ivec.push_back(rand() % 100);
cout << ivec[i] << " ";
};
//const int b = ivec.size();
auto b= ivec.size();
int a[b];
}


報錯的問題解決不了, b是 const int 型別,望大牛不吝賜教,非常感謝
uj5u.com熱心網友回復:
c++陣列必須是能在編譯器確定的const量,而不能是運行時期確定的只有c99可以用動態陣列,但是c無法用stl
uj5u.com熱心網友回復:
因為b的大小是未知的,你可以寫int a[sz] 也可以寫int *a = new int[b]轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/186647.html
標籤:C++ 語言
上一篇:關于鏈表的使用問題
下一篇:求大佬幫幫忙
