看板 C_and_CPP 關於我們 聯絡資訊
#include "stdafx.h" #include "iostream" using namespace std; int main(void) { int p=1; cout<<"How many numbers?"<<endl; cin>>p; int A[p]; for(int i=0;i<p; i++) { cin>>A[i]; } cout<<"Before sort:"<<endl; for(int i=0;i<p; i++) { cout<<A[i]<<endl; } return 0; } 我卻得到錯誤訊息: .\作業1.2.cpp(9) : error C2057: 必須是常數運算式 .\作業1.2.cpp(9) : error C2466: 無法配置常數大小為 0 的陣列 ,常數必須為大於 0 的整數 .\作業1.2.cpp(9) : error C2133: 'A' : 未知的大小 請問問題出在哪裡呢? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.4.235
QQ29: int A[p]; 03/17 12:02
QQ29:改成const int p吧 03/17 12:03
QQ29:不過你p要用輸入的得到 那只好用動態宣告了 03/17 12:04
stonehomelaa:c++就用vector呀 03/17 12:24
※ 編輯: Mason0218 來自: 140.112.4.234 (03/17 15:32)
Mason0218:瞭解了,謝謝 03/17 15:33