我剛剛學習數組,我的書幾乎沒有解釋如何輸入二維字符串數組。下面是我的書推薦碼:輸入多個字符串數組
char lastName[6][50];
for(int i = 0; i < 5; i++)
{
cout << "Enter candidates last name: ";
cin.get(lastName[i], 50);
cout << endl;
}
for(int j = 0; j < 5; j++)
{
cout << lastName[i] << endl;
}
與此代碼我只能輸入一個名稱和節目的其餘部分只是重複「輸入考生的名字:」
,我試過其他的代碼是:
for(int i = 0; i < 5; i++)
{
cout << "Enter candidates last name: ";
cin >> lastName[i][50];
cin.get(lastName[i], 50);
cout << endl;
}
Same output code
此代碼讓我輸入正確數量的名稱,但缺少每個名稱的第一個字符。示例「喬」給我「oe」
再次,我是一個初學者,我不明白爲什麼它不能正常工作。謝謝!
應該'j',而不是'i'在該行'的cout << lastName的[I] << ENDL;' –