1.2 c++_语句

来源:互联网 发布:windows网络编程第二版 编辑:程序博客网 时间:2024/05/20 05:55

1,声明、变量、赋值
2,cout的新用法
3,其他++语句

1,声明、变量、赋值

int testInt;
double testDouble;
testInt = 1;
testInt++;
testInt +=1;
testInt = 2+2;
testDouble = testInt = 1;
testDouble +=testInt;
赋值的顺序:从右往左

2,cout的新用法

cout << testInt << endl;
cout可以智能的识别出testInt的值,从而打印出 整型的1,而不是字符串“testInt”或者字符串“1”。
c中,要打印字符串“1”和整型1,可以使用printf();

3,其他c++语句

cin:用于程序的输入
cout:用于程序的输出

使用cin:
int testInt;
cout << “请输入一个整型:\n”;
cin >> testInt;
cout << “输入的整型是:”<< testInt << endl;

另外:cin.get() 能够在输入内容并且按下enter键的时候读取输入内容

原创粉丝点击