日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

c++基本语法

發布時間:2024/9/5 c/c++ 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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++基本语法的全部內容,希望文章能夠幫你解決所遇到的問題。

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