Microsoft Visual Studio,在调试中不显示unsigned char,截断int t [英] Microsoft Visual Studio, does not display unsigned char in debug, truncation of int t

查看:112
本文介绍了Microsoft Visual Studio,在调试中不显示unsigned char,截断int t的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始学习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;
}

推荐答案

编辑:最初我试图只指定-1到unsigned char,在没有运气之后,我尝试将-1放在单引号中。这是带单引号的代码,但即使没有引号我也有同样的问题。抱歉这个混乱
edit: originally I tried to assign just -1 to the unsigned char, and after not having luck with that I tried putting the -1 in single quotes '' . This is the code with the single quotes, but I have the same issue even without quotes. Sorry for that confusion


这段代码:

This code:

展开 | 选择 | Wrap | 行号


- 如果编译器使用两个'的补码格式,则将1存储为255。我不相信C标准要求使用两个补码。你必须非常努力地找到一个不使用两个补码表示法的编译器,但这不是重点。您依赖于实现定义的行为。
-1 is stored as 255 if the compiler uses two''s complement format. I don''t believe the C Standard mandates the use of two''s complement. You would have to look very hard to find a compiler that doesn''t use two''s complement notation, but that''s not the point. You are relying on implementation-defined behavior.


这篇关于Microsoft Visual Studio,在调试中不显示unsigned char,截断int t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆