toupper返回整数而不是char

toupper返回整数而不是char

本文介绍了toupper返回整数而不是char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 用于以下函数void display(){ for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (board[i][j] < 84 && (i+j)%2 == 0) SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 0x70); else if (board[i][j] < 84 && (i+j)%2 == 1) SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 0xc0); else if (board[i][j] > 97 && (i+j)%2 == 0) SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 0x7c); else if (board[i][j] > 97 && (i+j)%2 == 1) SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 0xc7); cout << " " << toupper(board[i][j]) << " "; } cout << endl; }} [8]它返回整数,所以我的输出看起来像instead of returning chars for the char board[8][8] it returns integers so my output looks like 82 78 66 81 75 66 78 82 80 80 80 80 80 80 80 80 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 80 80 80 80 80 80 80 80 82 78 66 81 75 66 78 82而不是预期的输出 R N B Q K B N R P P P P P P P P P P P P P P P P R N B Q K B N R 我也试过声明一个char a = board [i] [j] coutI have also tried declaring a char a = board[i][j]; cout << toupper(a); in an attempt to confirm the variable type as a character and received the same output.这是一个类的赋值,所以我不期望很多帮助,我只是想知道为什么我的函数是返回整数代替字符,所以我知道我的错误是为了未来的参考,谷歌没有多大帮助。是toupper的某种范围问题吗?this is an assignment for a class so i don't expect much help, i just want to know why my function is returning integers in place of chars so that i know what my mistake is for future reference, Google didn't help much. is it some sort of scope issue with toupper?推荐答案 Toupper函数返回大写等于c的值,如果这样的值存在, c(不变)。该值作为int值返回,可以隐式转换为char。Toupper function returns the uppercase equivalent to c, if such value exists, or c (unchanged) otherwise. The value is returned as an int value that can be implicitly casted to char. http://www.cplusplus.com/reference/cctype/toupper/ 这篇关于toupper返回整数而不是char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 18:54