问题描述
我最近开始学习C ++,为了练习练习,我使用的是Microsoft Visual Studio。
我试图重新创建初始化-1的效果一个unsigned char(因此返回255)。然而,当编译代码时,它显示为未定义,警告我将int截断为unsigned char,并警告我正在截断常量值。
我得到了一个int不会提升到一个unsigned char,但是不应该认识到-1转换为255作为unsigned char吗?或者我错过了使用Visual Studio特有的东西?
调试时,我尝试为unsigned char做一个cout,但只显示一个空格。以下是cc
澄清的代码:
#include" stdafx.h"
#include< iostream>
使用命名空间std;
int main()
{
unsigned char c =' '-1'';
cout<< c<< endl;
返回0;
}
Hi, I''ve recently started studying C++ and in order to practice exercises I am using Microsoft Visual Studio.
I am attempting to recreate the effect of initializing -1 to an unsigned char (thus returning 255). When compiling the code however, it shows as undefined, warning that I am truncating an int into an unsigned char, as well as warning that I am truncating a constant value.
I get that an int does not promote up to an unsigned char, but shouldn''t the ide recognize that -1 converts to 255 as an unsigned char? Or am I missing something that is particular to using Visual studio?
When debugging, I try to do a cout for the unsigned char, but only a blank space shows. Here is the code for cc
clarification:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
unsigned char c = ''-1'';
cout << c << endl;
return 0;
}
推荐答案
这篇关于Microsoft Visual Studio,在调试中不显示unsigned char,截断int t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!