Lesson01-07-20-C++高级数组
来源:互联网 发布:php过滤相同的数据 编辑:程序博客网 时间:2024/05/19 18:10
#include<iostream>#include<array>#include<vector>//C++的标准库#include<string>//C++字符串using std::array;//静态数组,栈上,using std::vector;//动态数组,堆上,using std::string;//使用C++风格数组不需要管理内存。//array注意不要栈溢出//array适用于任何类型void main1(){ // array<int, 5> myint = { 1, 2, 3, 4, 5 }; array<int, 1024 * 256> myint1; vector<double> myvector; //动态数组 for (int i = 0; i < 1024 * 1024; i++) { myvector.push_back(i);// } std::cin.get();}void main2(){ array<int, 5> myint1 = { 1, 2, 3, 4, 5 }; array<int, 5> myint2 = { 11, 12, 13, 14, 15 }; array<int, 5> myint3 = { 21, 22, 23, 24, 25 };//array<array<int, 5>, 3> myint = {myint1,myint2,myint3}; array<array<int, 5>, 3> myint = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; for (int i = 0; i < myint.size();i++)//数组大小 { for (int j = 0; j < myint1.size(); j++) { std::cout << " "<<myint[i][j]; } std::cout << "\n"; } std::cin.get();}void main3(){ vector <string> string1;//动态字符串数组 //可以反复利用 string1.push_back("notepad"); string1.push_back("calc"); string1.push_back("mspaint"); string1.pop_back();//删除一个 //string1.clear();//清空 for (int i = 0; i < string1.size(); i++)//遍历动态数组 { //system(string1[i].c_str()); }}void main5(){ vector <string> string1;//动态字符串数组 string1.push_back("notepad"); string1.push_back("calc"); string1.push_back("mspaint"); vector<string>::iterator ibegin, iend;//迭代器 ibegin = string1.begin();//数据起始点 iend = string1.end();//结束 for (;ibegin!=iend;ibegin++) { string tempstr = *ibegin;//获取指针指向的数据 system(tempstr.c_str());//执行指令 }}void main6(){ array<int, 5> myint = { 1, 2, 3, 4, 5 }; array<int,5>::iterator ibegin, iend;//正向迭代器 ibegin = myint.begin(); iend = myint.end(); while (ibegin!=iend) { std::cout << *ibegin << std::endl; ibegin++; } array<int, 5>::reverse_iterator rbegin, rend; rbegin = myint.rbegin(); rend = myint.rend(); while (rbegin!=rend) { std::cout << *rbegin << std::endl; rbegin++; } std::cin.get();}void main7(){ vector <string> string1;//动态字符串数组 string1.push_back("notepad"); string1.push_back("calc"); string1.push_back("mspaint"); //反向迭代器 vector<string>::reverse_iterator rbegin = string1.rbegin(); vector<string>::reverse_iterator rend = string1.rend(); //rend--;rend最后不指向数据,指向数据的结尾的下一个节点A:if (rbegin!=rend) { system((*rend).c_str());//执行指令 //rbegin++; rend--; goto A; }}
0 0
- Lesson01-07-20-C++高级数组
- C++lesson01
- C#Lesson01
- c语言lesson01
- lesson01 计算机科学
- C专栏8-高级类型数组
- 孙鑫VC++Lesson01
- Lesson01:HTML5 简介
- Lesson01-Homework UIView作业
- Lesson01 cpu与内存
- Java Script-Lesson01
- c++高级---C/C++中如何获取数组的长度
- c++高级---C/C++二维数组---与指针的关系
- C语言07指针高级
- Lesson01变量和基本类型
- NEHE的OpenGL代码Lesson01
- C++/C高级数据类型
- 数组的高级性能
- Spring事物配置的五种方式
- 常用的链接
- ps aux|grep
- Android selector标签下的几种状态解读
- Meteor数据库mongodb查询
- Lesson01-07-20-C++高级数组
- 2012年5月SAT香港真题解析
- HDU 2818 Building Block(带权并查集)
- stl泛型算法
- Apache+PHP+MYSQL部署
- ECMAScript 5严格模式
- hdu 1010
- poj 2255
- 反射