清除cin
输入的更好方法是什么?我想cin.clear
,这cin.ignore
是一个好方法?
码:
void clearInput()
{
cin.clear();
cin.ignore(1000,'\n');
//cin.ignore( std::numeric_limits<streamsize>::max(), '\n' );
}
Run Code Online (Sandbox Code Playgroud)
我老师给了我这个回复:
这基本上是说你的clearInput不起作用FYI:忽略绝不是一个好主意,可以摆脱所有遗留在一条线上
而你的测试失败正是为什么现在以正确的方式清除它的原因
她还告诉我以下内容:
忽略你需要猜测你想忽略多少个字符如果你完全知道你的数据并且它遵循严格的格式 - 就像在Excel电子表格中一样,忽略真的很好.如果你不在这种类型的文件中,那么你永远不要使用忽略.问题,您的数据是否格式良好?如果是,请使用ignore.如果没有,请不要使用ignore.
列出所有获取数据的方式?1)有提取>>
而且还有??????
请为我列出
我在一个文件中读到一个数组.它正在读取每个char,问题出现在它还在文本文件中读取换行符.
这是一个数独板,这是我在char中读取的代码:
bool loadBoard(Square board[BOARD_SIZE][BOARD_SIZE])
{
ifstream ins;
if(openFile(ins)){
char c;
while(!ins.eof()){
for (int index1 = 0; index1 < BOARD_SIZE; index1++)
for (int index2 = 0; index2 < BOARD_SIZE; index2++){
c=ins.get();
if(isdigit(c)){
board[index1][index2].number=(int)(c-'0');
board[index1][index2].permanent=true;
}
}
}
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
就像我说的那样,当它遇到\n时,它会读取文件,显示在屏幕上,但是顺序不正确
再一次相对简单的事情,但他们想要什么困惑.
在笛卡尔坐标系上求距离的方法是距离= sqrt [(x2-x1)^ 2 +(y2-y1)^ 2]
但我怎么在这里申请?
//Requires: testColor to be a valid Color
//Effects: returns the "distance" between the current Pixel's color and
// the passed color
// uses the standard method to calculate "distance"
// uses the same formula as finding distance on a
// Cartesian coordinate system
double colorDistance(Color testColor) const;
Run Code Online (Sandbox Code Playgroud)
颜色类定义了颜色:int红色,绿色,蓝色
我是否定义了类似'oldGreen''oldRed''oldblue'的东西,并获得那种距离?通过的颜色是红色,绿色,蓝色?
试图计算数组中有多少元素不等于0,设置错了?
我想检查数组中的所有值(它是一个数独的板),然后当所有元素都"满"时,我需要返回true.什么关闭?
bool boardFull(const Square board[BOARD_SIZE][BOARD_SIZE])
{
int totalCount=0;
for (int index1 = 0; index1 < BOARD_SIZE; index1++)
for (int index2 = 0; index2 < BOARD_SIZE; index2++){
if(board[index1][index2].number!=0)
totalCount++;
}
if(totalCount=81)
return true;
else
return false;
Run Code Online (Sandbox Code Playgroud) 这可能很容易,但我迷失了如何"确定"它在这个范围内..
所以基本上我们有class Color
很多功能可以从中实现.
我需要的这个功能是:
效果:将颜色值更正为0-255(含).如果值超出此范围,则调整为0或255,以较近者为准.
这是我到目前为止:
static int correctValue(int value)
{
if(value<0)
value=0;
if(value>255)
value=255;
}
Run Code Online (Sandbox Code Playgroud)
对不起这么简单的问题; /
我有一个按钮:
button3 = Button(app, text="Show Members", width=15, command=lambda: showLDAPMembers(yourName,yourPassword))
Run Code Online (Sandbox Code Playgroud)
如何将ENTER键绑定到它?我试过做:
app.bind('<Return>', showLDAPMembers(yourName,yourPassword))
Run Code Online (Sandbox Code Playgroud)
但是我得到了未解决的参考错误..
def showLDAPMembers(yourName,yourPassword):
app.lb.delete(0,END)
Run Code Online (Sandbox Code Playgroud) 这表明了翻转应该是什么以及镜子应该是什么。
两种类型镜子的代码:
void mirrorLeftRight()
{
for (int x = 0; x < width/2; x++) {
for (int y = 0; y < height; y++) {
int temp = pixelData[x][y];
pixelData[x][y]=pixelData[width-x][y]
pixelData[width-x][y]=temp;
}
}
}
void mirrorUpDown()
{
for (int x = 0; x < width; x++) {
for (int y = 0; y < height/2; y++) {
int temp = pixelData[x][y];
pixelData[x][y]=pixelData[x][height-y]
pixelData[x][height-y]=temp;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这看起来适合镜子吗?
对于翻转,只需使用width
并且height
不除以 2 即可?