日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

c++基本语法

發布時間:2024/9/5 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c++基本语法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

&傳引用

?

字符串:(類比OC中NSString

string就是一個字符數組

#include<string>

string a;

a.push_back('m');

a.pop_back();

a.size();

a.length();

a[1]='x';

?

if(a.find('x') != string::npos) {//字符串a中找到x

}

?

for(int i = 0; i < a.length(); i++) {

?cout<<a[i]<<endl;

//或者賦值操作 a[i] = 'a';

}

?

數組:(類比OC中NSArray)

#include<vector>

vector<int> a(5);

vector<int> b(100, 1);//b長度為100,默認值為1

for(int i = 0; i < a.size(); i++) {

cout<<a[i]<<endl;

}

a.size();

?

常量數組用大括號,如 vector<int> a = {1, 2, 3, 4, 5};

?

多個數組拼接:

例:

Vector<int> AB = {1};

Vector <int> A = {2, 3};

Vector <int> B = {4, 5};

AB.insert( AB.end(), A.begin(), A.end() ); AB.insert( AB.end(), B.begin(), B.end() );

?

字典:(類比OC中NSDictionary)

#include<map>

map<char, int> a;

a['m'] = 1;

?

a.find('x') == a.end();

?

map<int, bool> visited;

?

迭代器

map<char, int> b;

map<char, int>::iterator ite;

for(ite=b.begin(); ite != b.end(); ite++) {

cout<<ite.first<<endl;

cout<<ite.second<<endl;

}

?

集合

#include<set>

set<char> a;

?

a.insert('x')

a.erase('x');

?

if(a.find('x') != a.end()){

...

}

?

?

棧:

#include<stack>

?

stack<int> a;

a.push(1);

a.pop();

a.top();//棧頂元素

a.empty();

?

隊列

#include<queue>

queue<int> a;

a.push(1);

a.pop();

a.peek();//隊列頭元素

轉載于:https://www.cnblogs.com/yibinpan/p/9292065.html

總結

以上是生活随笔為你收集整理的c++基本语法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。