相关疑难解决方法(0)

警告 - 有符号和无符号整数表达式之间的比较

我目前正在使用Accelerated C++,并在练习2-3中遇到了一个问题.

程序的快速概述 - 程序基本上采用名称,然后在星号框架内显示问候语 - 即Hello!被*的框架包围着.

练习 - 在示例程序中,作者用于const int确定问候语和星号之间的填充(空格).然后,作为练习的一部分,他们要求读者询问用户输入他们想要填充的大小.

所有这一切似乎都很容易,我继续向用户询问两个整数(int)并存储它们并更改程序以使用这些整数,删除作者使用的整数,编译时虽然得到以下警告;

Exercise2-3.cpp:46:warning:有符号和无符号整数表达式之间的比较

经过一些研究后,似乎是因为代码试图将上述整数(int)之一与a进行比较string::size_type,这很好.但我想知道 - 这是否意味着我应该改变其中一个整数 unsigned int?明确说明我的整数是签名还是未签名是否很重要?

 cout << "Please enter the size of the frame between top and bottom you would like ";
 int padtopbottom;
 cin >> padtopbottom;

 cout << "Please enter size of the frame from each side you would like: ";
 unsigned int padsides; 
 cin >> padsides;

 string::size_type c = 0; // definition of c …
Run Code Online (Sandbox Code Playgroud)

c++ unsigned-integer

66
推荐指数
3
解决办法
17万
查看次数

标签 统计

c++ ×1

unsigned-integer ×1