gpt4 book ai didi

c++ - 使用 cin 更改二维字符串数组值

转载 作者:太空宇宙 更新时间:2023-11-04 15:17:48 26 4
gpt4 key购买 nike

const string astrDice[6][4]
{
{"M1" , "DM" , "AT" , "BK"},
{"M2" , "DM" , "BK" , "BK"},
{"M3" , "DM" , "BK" , "BK"},
{"M4" , "BK" , "AT" , "BK"},
{"M5" , "BK" , "AT" , "BK"},
{"M6" , "BK" , "AT" , "BN"}
};

cout << "Choose Side (1-6):";
int nSideChoice = 0;
cin >> nSideChoice; // will -1 later for ease of use to operator
cout << "Choose a Slot (1-4):";
int nSlotChoice = 0;
cin >> nSlotChoice; // will -1 later for ease of use to operator
cout << "Enter a New Value:";
string strNewSlot;
cin >> strNewSlot;

astrDice[nSideChoice - 1][nSlotChoice - 1] = strNewSlot;

在最后一行说“No Viable Overloaded”=。我想使用 nSideChoice 和 nSlotChoice 来更改数组中的选择。我仍在学习如何编写基本代码,现在只知道一些 C++ .这只是我一直在研究的一个测试程序,并且随着我学习新事物而不断变化。

最佳答案

看这一行:const string astrDice[6][4]

astrDice 是常量,你不能修改它!

编译器应该说类似error: passing 'const string' as 'this' argument of 'something' discards qualifier。当您看到这样的消息时,通常意味着您遇到了常量问题。

No Viable Overloaded "=" 不是有史以来最好的错误消息。它试图说明 std::string 没有 const operator=()。好吧,呃。

尝试理解错误消息很重要,即使它们有时有点愚蠢。您会节省很多时间。

关于c++ - 使用 cin 更改二维字符串数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27824423/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com