在此处short为16位 有符号的最大数为32767 最小数为-327668。
hex 十六进制 oct 八进制
#include<iostream>
using namespace std;
int main()
{
char code;
cout<<"Enter your code:____\b\b\b\b";
cin>>code;
cout<<"you input "<<code<<endl;
return 0;
}
\b 使光标回到第一个下划线处,输入多个字符后,只输出一个字符!!
cout 输出时不用指定输出类型,它会根据变量定义的类型进行输出!进行输出时只需<<变量名 即可
float 的精度为6~7位,double为15~16位
%求模 生成第一个数除以第二个数的余数
当涉及两种运算类型时,较小的类型被转化为较大的类型。
"S" 字符串常量,表示两个字符,即S和\0字符。 而‘S’是字符常量 。
共用体可以用来存储多种类型的变量,条件是在不同的时间内进行,它的长度为其最大成员的长度。
如果给cout提供一个指针,它将打印地址。但如果指针的类型为char * ,则cout将显示指向的字符串。
#include <iostream>
#include <string>
using namespace std;
int main()
{
int *p1=new int;
*p1=10;
char *p2="zonghua";
cout<<p1<<"the number is:"<<*p1<<endl;
cout<<p2<<endl;
delete p1;
return 0;
}
使用new创建动态结构
#include <iostream>
using namespace std;
struct good
{
char name[20];
float volume;
double price;
};
int main()
{
good *p=new good;
cout<<"Enter name:";
cin.get(p->name,20);
cout<<"Enter volume:";
cin>>p->volume;
cout<<"Enter price:";
cin>>p->price;
cout<<(*p).name<<endl;
cout<<p->volume<<endl;
cout<<p->price<<endl;
delete p;
return 0;
}