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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

补8-5日复习内容 STL 标准模板库的容器

發(fā)布時(shí)間:2025/3/19 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 补8-5日复习内容 STL 标准模板库的容器 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

//有關(guān) STL 標(biāo)準(zhǔn)模板庫(kù)的函數(shù)

/* string 的 */

/*

#include <iostream>

#include <string>

#include <windows.h>

using namespace std;

void stringinit()

{

string s1; //無(wú)參構(gòu)造函數(shù)

string s2("helloworld"); //有參構(gòu)造函數(shù)

string s3(10,'h'); //

string s4(s2); //拷貝構(gòu)造函數(shù)

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);

cout << s1 << endl;

cout << s2 << endl;

cout << s3 << endl;

cout << s4 << endl;

}

void stringat() //數(shù)據(jù)的存儲(chǔ)

{

string s1("123456789");

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);

cout << s1[2] << endl; //可能會(huì)段錯(cuò)誤(越界

cout << s1.at(1) << endl; //可以拋出異常(越界 具體如下

try

{

cout << s1.at(10) << endl;

}

catch (exception &e)

{

cout << e.what() << endl;

}

}

?

void stringlength()

{

string s1("helloworld");

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |

FOREGROUND_BLUE);

cout << s1.length() << endl;

?

string s2;

if (s2.empty())

{

cout << "empty string" << endl;

}

}

?

void stringstr()

{

string s1("helloworld");

const char *ptr = s1.c_str();

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |

FOREGROUND_BLUE);

cout << ptr << endl;

}

?

void stringcopy()

{

string s1("yohoo");

char buf[32] = {0};

s1.copy(buf,3,2);

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |

FOREGROUND_BLUE);

cout << buf << endl;

}

?

int main()

{

//stringinit();

//stringat();

//stringlength();

//stringstr();

//stringcopy();

?

system("pause");

return 0;

}

*/

?

/* vector */

/*

#include <iostream>

#include <vector>

?

#include <windows.h>

?

using namespace std;

?

void vectorinit()

{

int array[10] = {0,1,2,3,4,5,6,7,8,9};

vector<int> v1;

vector<int> v2(10);

?

vector<int> v3(array , array + sizeof(array) / sizeof(array[0]));

?

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

{

cout << v3[i];

}

cout << endl;

?

vector<int> v4(v3);

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

{

cout << v4[i];

}

cout << endl;

?

cout << v4.at(2) << endl;

cout << v4[5] << endl;

}

?

void vectorassgin()

{

int array[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

vector<int> v3(array, array + sizeof(array) / sizeof(array[0]));

?

vector<int> v1;

v1.assign(array, array + sizeof(array) / sizeof(array[0]));

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

{

cout << v1[i];

}

cout << endl;

?

v1.assign(5 , 'a');

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

{

cout << v1[i];

}

cout << endl;

?

v1.swap(v3);

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

{

cout << v1[i];

}

cout << endl;

?

}

?

void vectoriterator()

{

vector<int> v1(10,0);

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

{

v1[i] = i + 1;

}

for (vector<int>::iterator it = v1.begin(); it != v1.end(); it++)

{

cout << *it;

}

cout << endl;

}

?

void vectorinsert()

{

?

}

?

int main()

{

//vectorinit();

//vectorassgin();

?

vectoriterator();

vectorinsert();

?

system("pause");

return 0;

}

*/

?

/* deque */

/*

#include <iostream>

#include <deque>

?

#include <windows.h>

?

using namespace std;

?

int main()

{

?

/*

deque <int> d1;

d1.push_back(1);

d1.push_back(2);

d1.push_back(3);

d1.push_back(4);

d1.push_back(5);

?

d1.push_front(99);

?

for (deque<int>::iterator it = d1.begin(); it != d1.end(); it++)

{

cout << *it<<" ";

}

cout << endl;

*/

/*

int array[10] = {3,1,4,7,3,6,4,3,1,3};

deque <int> d1(array,array + sizeof(array) / sizeof(array[0]));

?

for (deque<int>::iterator it = d1.begin(); it != d1.end();)

{

if (*it == 3)

{

it = d1.erase(it);

}

else

{

it++;

}

}

?

for (deque<int>::iterator it = d1.begin(); it != d1.end(); it++)

{

cout << *it << " ";

}

cout << endl;

?

?

system("pause");

return 0;

}

*/

?

/* stack */

?

#include <iostream>

#include <stack>

?

using namespace std;

?

int Priority(char ch)

{

switch(ch)

{

case '(':

return 3;

case '*':

case '/':

return 2;

case '+':

case '-':

return 1;

default:

return 0;

}

?

}

?

int main()

{

int i = 0, tmp = 0, num1, num2, result;

stack<int> s_opt, s_num;

char opt[64] = {0};

char ch;

?

cout << "Please input :" << endl;

cin >> opt;

?

while (opt[i] != '\0' || s_opt.empty() != true)

{

if (opt[i] >= '0' && opt[i] <= '9')

{

tmp = tmp * 10 + opt[i] - '0';

i++;

if (opt[i] > '9' || opt[i] < '0')

{

s_num.push(tmp);

tmp = 0;

}

}

else

{

//操作符進(jìn)棧

if (s_opt.empty() || (s_opt.top() == '(' && opt[i] != ')')

|| Priority(opt[i]) > Priority(s_opt.top()))

{

s_opt.push(opt[i]);

i++;

continue;

}

?

if (s_opt.top() == '(' && opt[i] == ')')

{

s_opt.pop();

i++;

continue;

}

?

if ((opt[i] == ')' && s_opt.top() != '(') ||

Priority(opt[i]) <= Priority(s_opt.top()) || (opt[i] == '\0' && !s_opt.empty()))

{

ch = s_opt.top();

s_opt.pop();

switch(ch)

{

case '+':

num1 = s_num.top();

s_num.pop();

num2 = s_num.top();

s_num.pop();

s_num.push(num1 + num2);

break;

case '-':

num1 = s_num.top();

s_num.pop();

num2 = s_num.top();

s_num.pop();

s_num.push(num2 - num1);

break;

case '*':

num1 = s_num.top();

s_num.pop();

num2 = s_num.top();

s_num.pop();

s_num.push(num1 * num2);

break;

case '/':

num1 = s_num.top();

s_num.pop();

num2 = s_num.top();

s_num.pop();

s_num.push(num2 / num1);

break;

}

}

}

}

result = s_num.top();

?

cout << result << endl;

return 0;

}

總結(jié)

以上是生活随笔為你收集整理的补8-5日复习内容 STL 标准模板库的容器的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。