C++要用的

1.整数转字符串

string s = to_string(n);

 

2.char 转 int

char a = '2';

int n = a - '0';

 

3.string 转 int

string s;

int n = std::stoi(s);

 

4.生成[start,end]之间的随机数

 int k = (rand() % (end-start+1))+start;

 

5.string截取

 s.substr(pos, n)    截取s中从pos开始(包括0)的n个字符的子串,并返回

 

6.auto关键字遍历vector方式

eg:   vector<int>  nums;

       for(auto x:nums)

 

7.istringstream、ostringstream和ststream

(1)istringtream: 串流的输入

(2)ostringtream: 串流的输出

(3)strstream: 串流的输入输出

(4)头文件: #include<sstream>

(5)具体使用:

Part1.空格分隔

eg: string s = "I am a student", str;  

     istringstream ss(s);

     while(ss>>str){

          cout<<str<<endl;

      }

Part2.逗号分隔

eg:   string s = "I,am,a,student";

        istringtream ss(s);

       string str;

     while(getline(ss,str,",")){

            cout<<str<<endl;

       }

 

8.set用法

(1)头文件: #include<set>

(2)set会对压入的数据进行排序

        从小到大: set<int,less<int>> M;

     从大到小:  set<int,greater<int>> M;

 

9.queue使用

(1)头文件: #include<queue>

(2)常用函数

         1.入队: a.push(2);

       2.出队:   a.pop();

     3.队首元素:  a.front();

     4.队尾元素:  a.back();

    5.判断队列为空: a.empty()

   6.获取队列大小: a.size()

 

10.删除字符串中的一个字符

          string.erase(pos=0,length):    表示从pos开始(包括pos),删除length长的字符串

 

11.字母字符串大小写转换

       (char)toupper()

      (char)tolower()

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值