Java 转 C++注意事项

Java 转 C++注意事项

学习自 :

https://www.liuchuo.net 柳大神的**《从C语言转C++简明教程 v5.0+》**

以前刷题的时候用的是Java,由于ccf建议用c++,且c++在刷算法题上优于Java,遂学习C++ .以下是简单的STL 用法.使用方法和注意事项都在注释里了.多练练应该就可以了 QVQ


# include <iostream> 
#include <algorithm>
using namespace std;
#include <vector>
#include <set>
#include <string>
#include <map>
#include<stack>
#include<queue>
#include<bitset>
void func(int& a)
{
	a = 99;
	// 会改变a 的值
}
void fun(int a)
{
	a = 99;
	//不 会改变a 的值
}
bool cmp(int a, int b)
{
	return a > b;
}
int main()
{
	/*cin>> a;
	cout <<a<<"sss"<<endl;*/

	/*string b = "ssss";
	string s4;
	cin >> s4;
	cout << s4;*/

	//string s;
	//cout << s.length();
	//字符长度

	/*int a = 0;
	fun(a);
	cout << a <<endl;
	func(a);
	cout << a<<endl;*/
	//vector<int> v1;
	//cout << v1.size()<<endl; //输出大小
	//v1.resize(8);
	//cout << v1.size()<<endl; //输出大小
	//v1[3] = 2;
	//cout << v1[3] << endl; //输出
	/*for (int i = 0;i<v1.size();i++)
	{
		cout << v1[i] << endl;
	}*/
	/*for (auto it = v1.begin(); it != v1.end(); it++)
	{
		cout << *it << endl;
	}*/
	//set<int>s;
	//s.insert(1);// 插入1
	//cout << *(s.begin()) << endl;
	//for (int i = -10; i < 0; i++)
	//{
	//	s.insert(i);
	//}
	//for (auto it = s.begin(); it != s.end(); it++)
	//{
	//	cout << *it << " " << endl;
	//	// 自动按照从小到大的顺序排序
	//}
	//cout <<" ----" << endl;
	//cout << (s.find(1) != s.end()) << endl;
	//// 找得到 1   返回 1
	//s.erase(1);
	//cout << (s.find(1) != s.end()) << endl;
	//// 找不到 1     返回0

	//map<string, int> m;
	//m["hello"] = 2;
	//cout << m["hello"] << endl;
	//m["world"] = 3; 
	//m[","] = 1;
	//for (auto it = m.begin(); it != m.end(); it++) 
	//{ 
	//	cout << it->first << " " << it->second << endl;
	//} // 遍历     it->first 输出 键    it->second  输出值 

	//栈
	/*stack<int> s;
	for (int i = 0; i < 6; i++)
	{
		s.push(i);
	}
	cout << s.top() << endl;
	cout << s.size() << endl;
	s.pop();
	cout << s.top() << endl;
	cout << s.size() << endl;*/

	//队列
	//queue<int > q;
	//for (int i = 0; i < 6; i++)
	//{
	//	q.push(i);
	//}
	//cout <<q.front()<<" "<< q.back()<< endl;
	//// 输出  队首  与  队尾元素
	//cout <<"ss"<< endl;

	//二进制位
	//bitset<8> b{ "11" };
	//// 5 表示5个二进制位
	//for (int i = 0; i < 5; i++)
	//{
	//	cout << b[i] << endl;
	//}
	//cout <<"b中是否存在1 的二进制位 " << b.any() <<endl;
	////b中是否存在1 的二进制位
	//cout <<"b中不存在1 吗?  " << b.none() << endl ;
	////b中不存在1 吗?
	//cout <<"b中1 的二进制位个数  " << b.count() << endl;
	////b中1 的二进制位个数
	//cout << "b中二进制位的个数 " << b.size() << endl ;
	////b中二进制位的个数
	//cout << "测试下标为2出是否二进制位为1 " << b.test(2) << endl ;
	////测试下标为2出是否二进制位为1
	//b.set(4);//把b的下标为4 处 置为 1
	//b.reset();//所有位 归零
	//b.reset(3);//b 的下标3 处 归零
	//b.flip(); // b 的所有二进制位 逐为 取反

	//sort函数
	//  #include <algorithm>
	//vector<int> v(10);
	//for (int i = 0; i < 10; i++)
	//{
	//	v[i] = i*-2;
	//}
	//sort(v.begin(), v.end());
	//// 没有传参数 cmp,所以默认 从小到大排序
	//for (int i = 0; i < 10; i++)
	//{
	//	cout <<v[i]<<"  ";

	//}
	//cout <<" "<< endl;

	//int arr[10];
	//for (int i = 0; i < 10; i++)
	//{
	//	arr[i] = i;
	//}
	//sort(arr, arr + 10, cmp);
	//for (int i = 0; i < 10; i++)
	//{
	//	cout << arr[i] << "  ";
	//}
	//// 设置了 cmp ,所以按照   大到小的顺序排序
	
	//判断是否是字母
	//char c;
	//cin >> c;
	//if (isalpha(c))
	//{
	//	cout << c<<"is alpha  是字母"<< endl;
	//}
	//if (islower(c))
	//{
	//	cout << c << " is alpha  小写字母" << endl;
	//}
	//if (!isupper(c))
	//{
	//	cout << c << " is alpha 不是大写字母" << endl;
	//}

	//大小写转化
	//char a = 'A';
	//cout << tolower(a)<< endl;
	//char t = tolower(a);
	//cout << t << endl;
	return 0;
}

发布了96 篇原创文章 · 获赞 11 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_41852212/article/details/102158350