C转C++的学习笔记

useing namesapce

cpp 复制代码
#include <iostream>//输入输出流

//在前面加c
using namespace std;//std为名称空间
//避免函数重复

cin 和 cout

cpp 复制代码
#include <iostream>//输入输出流

//在前面加c
using namespace std;//std为名称空间
//避免函数重复

int main()
{
	int n = 0;
	cin >> n;//输入什么,等价于 scanf("%d", &n);
	cout << "hello guet!" << ++n << endl;//输出,endl就是\n

	//没有using namespace std;的情况下
	//std::cin >> n;//输入什么,等价于 scanf("%d", &n);
	//std::cout << "hello guet!" << ++n << std::endl;//输出,endl就是\n
	//std::cout << n++ << "\n";

	return 0;
}

//运算速度不如scanf,printf

变量声明

c 复制代码
//
//int main()
//{
//	int n = 0;
//	cin >> n;
//	for (int i = 0; i < 10; i++)
//	{
//		cout << n << " ";
//	}
//	cout << endl;
//
//	for (int i = 0; i < 10; i++)
//	{
//		cout << n + 1 << " ";
//	}
//
//
//	return 0;
//}

bool变量

cpp 复制代码
#include <iostream>
using namespace std;

//еbool
//int main()
//{
//	bool flag = true;
//	bool flag2 = -1;
//	bool flag3 = 0;
//
//	cout << flag << endl;
//	cout << flag2 << endl;
//	cout << flag3 << endl;
//
//	return 0;
//} 

const定义常量

cpp 复制代码
#include <iostream>
using namespace std;
//宏定义
//int main()
//{
//	const int Max = 150;//看作宏定义
//
//	//Max = 100;不可改变
//
//	cout << Max << endl;
//
//	return 0;
//}

string类

cpp 复制代码
#include <iostream>
#include <string>
using namespace std;

字符串拼接
//int main()
//{
//	//string s = "hello";
//	string s = "hello world";
//	string s_sub = s.substr(6, 5);
//	cout << s_sub << endl;
//
//	string s1 = " xixi";
//	string s2 = s + s1;
//
//	//cin >> s;
//	//输入带有空格:
//	getline(cin, s);
//	cout << s << endl;
//	//cout << s2 << endl;
//	cout << s.length() << endl;
//
//	return 0;
//}

结构体

cpp 复制代码
#include <iostream>
using namespace std;

//ṹ

//struct stu
//{
//	string name;
//	int age;
//};
//
//
//int main()
//{
//	//Cԣ
//	//struct stu s[10];
//
//	//c++
//	stu a[10];
//
//	return 0;
//}

引用&

cpp 复制代码
#include <iostream>
using namespace std;
//void c(int &a)
//{
//	a += 1;
//}
//
//int main()
//{
//	int a = 4;
//
//	c(a);
//
//	cout << a << endl;
//
//	return 0;
//}

vector

set

map(键值对)

stack(栈)

queue(队列)

unordered_map和unordered_set

bitset 位运算

sort函数

cctype头文件

C++11特性

auto声明

基于范围的for循环

to_string

stoi stod

相关推荐
艾莉丝努力练剑12 分钟前
【LeetCode&数据结构】单链表的应用——反转链表问题、链表的中间节点问题详解
c语言·开发语言·数据结构·学习·算法·leetcode·链表
人生游戏牛马NPC1号2 小时前
学习 Flutter (三):玩安卓项目实战 - 上
android·学习·flutter
还债大湿兄2 小时前
《C++内存泄漏8大战场:Qt/MFC实战详解 + 面试高频陷阱破解》
c++·qt·mfc
没有羊的王K5 小时前
SSM框架学习——day1
java·学习
珊瑚里的鱼5 小时前
LeetCode 692题解 | 前K个高频单词
开发语言·c++·算法·leetcode·职场和发展·学习方法
AI+程序员在路上5 小时前
QTextCodec的功能及其在Qt5及Qt6中的演变
开发语言·c++·qt
Risehuxyc5 小时前
C++卸载了会影响电脑正常使用吗?解析C++运行库的作用与卸载后果
开发语言·c++
不知道叫什么呀6 小时前
【C】vector和array的区别
java·c语言·开发语言·aigc
秋说6 小时前
【PTA数据结构 | C语言版】顺序队列的3个操作
c语言·数据结构·算法
林林要一直努力7 小时前
AOSP Settings模块问题初窥
android·学习·bug·android studio