我寫了這個代碼:存儲從一個字符數組中的值到另一個字符數組
shuffledteamnames[8][80]; // global
winningteamnames[8][80]; // global
int main()
{
if (team1 > team2)
{
cout << shuffledteamnames[index1] << " beat the " << shuffledteamnames[index2] << " " << team1 << "-" << team2 << " in a game 1." << endl;
winningteamnames[WINTEAMcounter] = shuffledteamnames[index1];
}
else if (team1 < team2) // index1 = 0, index2 = 1, WINTEAMcounter = 0
{
cout << shuffledteamnames[index2] << " beat the " << shuffledteamnames[index1] << " " << team1 << "-" << team2 << " in a game 1." << endl;
winningteamnames[WINTEAMcounter] = shuffledteamnames[index2];
}
}
的shuffledteamnames
輸出是這樣的:
Trojans
Bruins
Bears
Trees
Ducks
Beavers
Huskies
Cougars
我想創建一個競爭支架在那裏我將每一輪的獲勝者都放入char陣列winningteamnames
。我知道這些是二維字符數組,所以我需要將數據輸入到兩個參數中,但我不確定如何做到這一點。請讓我知道,如果我在任何時候都含糊不清,我非常感謝所有的幫助。
你缺少你的隊名數組聲明的'char'類型?爲什麼你不使用'std:string' – Barmar
我們不允許使用字符串或向量 – user3255966
http://en.cppreference.com/w/cpp/string/byte/strcpy –