提问者:小点点

C++变量不能从一个变量中复制[closed]


P1_choice变量正确存储数据,但无法复制\覆盖TTT数组

我希望将从用户获得的数据存储在p1_choice变量中,以ttt[0}数组

请不要拒绝投票,因为我是新来的,我试着遵循所有的指导方针,包括如何正确地提问。

#include <iostream>
#include <cmath>

using namespace std;

//CREATING VARIABLES
string ttt[9] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
string p1_choice;
int p2_choice;
int gametime = 20;

int main()
{
    while (gametime < 21) {
        cout << endl;
        gametime++;
        cout << "::: " << ttt[0] << " :: " << ttt[1] << " :: " << ttt[2] << " :::" << endl;
        cout << "::: " << ttt[3] << " :: " << ttt[4] << " :: " << ttt[5] << " :::" << endl;
        cout << "::: " << ttt[6] << " :: " << ttt[7] << " :: " << ttt[8] << " :::" << endl;

        cout << "PLAYER 1 ENTER YOUR COICE HERE........";
        cin >> p1_choice;
        cout << p1_choice << endl;
        p1_choice = ttt[6];
        cout << "::: " << ttt[6]
    }

    return 0;
}

共1个答案

匿名用户

如果您想要覆盖一个变量,您必须这样使用赋值运算符:var_to_overwrite=new_value;

您在代码中做了相反的事情。

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(c++|变量|从一|变量|中|复制|closed)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?