下面的代碼失敗:C++:如何使用char/string 2d數組接受來自用戶的超過1個參數?
#include <iostream>
#include <string>
using namespace std;
int main(){
int a, b;
cout << "how many input you want to give ? ";
cin >> a;
b = a - 1;
string str[b];
for(int i = 0; i <= b; i++){
cout << "Enter a string: ";
getline(cin, str[i]);
}
for(int k = 0; k < a; k++){
cout << "You entered: " << str[k] << endl;
}
return 0;
}
但如果我固定的值「詮釋了」,然後運行代碼。請幫忙。