我的 CIN 命令完全跳过输入?我什么都试过了
My CIN command skips input entirely? I've tried everything
#include <iostream>
#include <ctime>
#include <limits>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
int a, b;
int I, P;
unsigned int x;
unsigned int y;
int n, m;
unsigned int X, O;
int tictac[3][3] = {
{1, 1, 1},
{1, 1, 1} ,
{1, 1, 1} };
cout << "Player 1, enter X or O:" << endl;
cin >> a;
while (a == X);
{
cout << "Now, fill in the desired coordinated in a 3x3 square, a[x][y]" << endl;
cout << "Enter 'x' in [x]" << endl;
cin.ignore (std::numeric_limits<std::streamsize>::max(), 'n');
cin >> x;
cout << "Enter 'y' in [y]" << endl;
cin.ignore (std::numeric_limits<std::streamsize>::max(), 'n');
cin >> y;
tictac[x][y] == X;
}
}
我正在编写一个程序,让2名玩家在3x3网格上玩tictactoe,而其余的"CIN"命令拒绝接受输入。
我尝试将"CIN"命令更改为:
getline (cin, x)
getline (cin, y)
尝试将变量从(Unsigned int(更改为(Signed int(,并使用cin.ignore((命令,但问题仍然存在。
unsigned int X, O;
int tictac[3][3] = {
{1, 1, 1},
{1, 1, 1} ,
{1, 1, 1} };
cout << "Player 1, enter X or O:" << endl;
cin >> a;
while (a == X);
在最后一行中,X
还没有初始化,所以您将a
的值与任何特定值进行比较。此外,末尾的分号使循环重复一个空语句。
tictac[x][y] == X;
这是一个你丢弃了其结果的比较。使用=
进行分配。
相关文章:
- 是什么导致了Unity 3D中的"错误线程异常"?
- 是什么导致了这种使用三进制而不是短整型的有符号int到无符号int转换
- 在使用包含冒号的类似函数的宏时,是什么导致了这种编译器差异?
- 究竟是什么设置了_WIN32或_WIN64预处理器?
- 使用 std::istream_iterator 时,它似乎跳过了空文件行 - 如果可能的话,如何避免这种情况?
- C++:是什么导致了这个堆栈粉碎错误?
- 是什么解释了这个片段中如此多的移动和破坏
- 是什么阻止了 std::to_chars 和 std::from_chars 的实施
- C++ For Loop在过程中被跳过了.如何解决?
- 是什么给了 std::future 一些共享状态
- 是什么导致了构造函数之后的这些"意外令牌"错误?
- 什么保证了slice_array类操作员的行为?
- C++跳过了辛线
- 如何在我的代码中修复无穷循环?我认为它跳过了第二个CIN,因此它一直在循环
- C++:无论如何,有什么可以知道是什么触发了 If 语句
- 是什么破坏了这个多维数组的堆栈
- 是什么导致了代码中出现"error LNK2005: already defined in .obj"错误?
- QT Qtimeline跳过了第一个框架
- 为了对象替换的目的,究竟什么构成了对象的"name"?
- 我的 CIN 命令完全跳过输入?我什么都试过了