C ++ Source帮助,cout函数帮助

时间:2010-10-29 20:13:06

标签: c++ cout

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

#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 Express Edition。

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

2 个答案:

答案 0 :(得分:10)

 cout << "and that minus " c << " is" << a + b - c << endl;
 //                       ^

您错过了<<


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

支持的整数的确切范围取决于平台。通常,unsigned short支持0到65535范围内的值,signed short支持-32768到32767.

答案 1 :(得分:2)

cout << "and that minus " c << " is" << a + b - c << endl;

你错过了一个“&lt;&lt;&lt;”在字符串“和减去”和短c之间。

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

相关问题