C++基础1---C++入门

122 篇文章 1 订阅
120 篇文章 1 订阅

学习网站:C语言网.
C语言基础:C语言基础.
编译器:Red Panda Dev-C++



1.第一个C++程序

#include <iostream>		// 文件包含;包含iostream标准库; 
using namespace std;	// 声明使用一个叫std命名空间; 
int main(){
	cout << "Hello World." << endl;
	cout << "Welcome to the C++ world." << endl;
	return 0;
}

2.命名空间

// 1.命名空间:解决多个模块间命名冲突的问题;
#include <iostream>
using namespace std;
int main(){
    cout << "Hello C++." << endl;
    return 0;
}

// 2.域限定符::
#include <iostream>
int main(){
    std::cout << "Hello C++." << std::endl;
    return 0;
}

// 3.用using和域限定符一起限定用哪些名字
#include <iostream>
using std::cout;
using std::endl;
int main(){
    cout << "Hello C++." << std::endl;
    return 0;
}

3.输入输出

// 1.C++输入输出可以使用printf和scanf函数实现;
// 2.C++输入输出流使用cin和cout表示,使用前需要包含标准库iostream;
#include <iostream>
using namespace std;
int main(){
    cout << "Hello C++." << endl;	// endl起到换行作用;
    cout << "Welcome to FUXI." << "I am Willard." << endl;
    return 0;
}


// cin输入流:接收一个数据前,先定义一个与之类型一致的变量,用来存放这个数据
// 然后利用cin搭配>>输入操作符,来接收用户从键盘的输入;
#include <iostream>
using namespace std;
int main(){
	int numberOne;
	int numberTwo;
	
	cout << "Please input one number:" << endl;
	cin >> numberOne >> numberTwo;
	
	cout << "The value of numberOne is:" << numberOne << endl;
	cout << "The value of numberTwo is:" << numberTwo << endl;
	
	return 0;
}
  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鱼香Ross

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值