首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++源帮助、cout函数帮助

C++源帮助、cout函数帮助
EN

Stack Overflow用户
提问于 2010-10-30 04:13:06
回答 2查看 606关注 0票数 2

我是C++的新手,实际上我正在学习,在实验部分,然而,在实验时我遇到了cout函数的问题。编译时程序失败。我想知道你们是否可以帮助我:这是我写的源码。

代码语言:javascript
复制
#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
 signed short int a;
 signed short int b;
 signed short int c;
 a = 25;
 b = 8;
 c = 12;

 cout << a << endl;
 cout << b << endl;
 cout << c << endl;
 cout << "What is the sum of a + b - c? The answer is: ";
 cout << a + b - c;
 cout << endl;
 cout << "Why is this?" << endl;
 cout << "This is because: ";
 cout << "a + b equals: " << a + b << endl;
 cout << "and that minus " c << " is" << a + b - c << endl;
 cout << "If that makes sense, then press enter to end the program.";

 cin.get();
 return 0;


}

我正在使用Visual C++ 2008速成版。

感谢任何能指出我的错误并帮助我的人!

EN

回答 2

Stack Overflow用户

发布于 2010-10-30 04:15:28

代码语言:javascript
复制
 cout << "and that minus " c << " is" << a + b - c << endl;
 //                       ^

您缺少一个<<

unsigned表示该数据类型只能存储非负整数,而signed表示它也可以存储负整数(因为在中它可以有一个负“符号”)。

支持的整数的确切范围与平台相关。通常,unsigned short支持0到65535范围内的值,signed short支持-32768到32767范围内的值。

票数 10
EN

Stack Overflow用户

发布于 2010-10-30 04:18:57

代码语言:javascript
复制
cout << "and that minus " c << " is" << a + b - c << endl;

字符串“和那个减号”和短c之间缺少"<<“。

有符号意味着有一位专门用于确定值是否为负数,但这也意味着您不能拥有像使用无符号时那样大的数字。默认情况下,变量是有符号的,除非您另行指定。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4055539

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档