cout << "It is your turn " << name << endl;
cout << "Please type the piece you want to move in this form: x,y" << endl;
int xSrc, ySrc;
char buffer[4];
buffer[3] = '\0';
//Check input
try {
cin >> buffer;
cin.get(buffer, 4);
cout << std::cin.gcount() << " characters read: " << buffer << '\n';
xSrc = buffer[0];
ySrc = buffer[2];
cout << "What u wrote:" << xSrc << " " << ySrc << endl;
if (cin.fail()) {
cin.clear();
throw "Your input isn't formatted correctly:";
}
}
我正在创造一个国际象棋游戏。玩家通过以下方式输入他们想要移动棋子的坐标:2,2
由于某种原因,我的缓冲区没有获得第一个2.缓冲区只包含,2
为什么会这样?