C++ 学习之路 - 基本操作

C++ 基本语言

// 引入 in and out stream
#include
这个语句可以引入cout 或 cin;
如:

#include <iostream>
using namespace std;
int main() {
	cout << "please input your name" << endl;
	cin >> name;
	return 0;
}

其中 cout 指的是 c++ 语言中的 output;
cin 指的是 c++ 语言中的 input;
endl 指的是 end line;
是不是好记很多。

// 定义标准命名空间
using namespace std;

// 定义主函数

#include <iostream>
using namespace std;
int main() {
	//please input your codes here
	return 0;
}

此时记住初学者需要打两个花括号,不然容易忘记。

// 定义变量类型, 其中bites 指空间字节数。
整型:int (4 bites); long (8 bites); short (8 bites); long long (16 bites)
浮点型: float (4 bites); double (8 bites); long double (16 bites)
非字符: string (32 bites);
bool (1 bite) 用于定义True 或 False;
char (1 bite);
void (1 bite) void 没有类型;

// 命名规则:
开头: _ 或 a-zA-Z;
中间可以有数字,下划线;
一般用意思表达:
如: my father’s name: FatherName 或者 father_name;

// 定义常量
const int PI = 3.1415;
其中const 是 constant, 原来一般用 #define 来定义。

// 运算符(条件运算符,逻辑运算符,算数运算符)

  1. 条件运算符
    Exp1 ? Exp2 : Exp3;
    如果Exp1 为真,则执行Exp2,否则执行Exp3;
    如:
#include <iostream>
using namespace std;
int main() {
	// identify pass line according to gender
	string gender;
	float PassLine;
	cout << "please input your gender:" << endl;
	cin >> gender;
	PassLine = (gender == "female" ? 12.5 : 9.5);
	cout << "your pass line is" << PassLine << endl;
	return 0;
}
  1. 逻辑运算符
    与或非: &&; ||; !;

  2. 算数运算符
    加减:+, - ;
    乘除余:*, /, % ;
    次方: ^ ;
    … …

今天总结就到这里了,明天继续。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值