#include <iostream>
#include <string>
#include <vector>
using namespace std; int main()
{
vector<vector<string> > edge; //注意<string>后有一个空格符号
vector<string> stemp(); //将列的个数设置为2
  
for(int i = ;i<;i++) //此处参数5表示将行数设置为5
{
cin>>stemp[]>>stemp[];
edge.push_back(stemp);
} for(int j=;j<edge.size();j++)
{
cout<< j+<<": "<<edge[j][]<<" , "<<edge[j][]<<endl;
}return ;
}
//eg
#include <iostream>
#include <vector>
using namespace std; int main()
{
vector<vector<int> > a;
vector<int> stmp(); //set the colCount=5
for (int i = ; i < ; i++) //set the rowCount=5
{
for (int j = ; j < ;j++)
{
stmp[j] = (i+)*(j+);
cout << stmp[j] << " ";
}
cout << endl;
a.push_back(stmp);
}
int rowCount = a.size(); //get the rowCout from a two-dimensional array
int cloCount = a[].size(); //get the colCout from a two-dimensional array
cout << "row: " << rowCount << endl;
cout << "col: " << cloCount << endl;
return ;
}

//注:如果二维数组是如 int a[15][8]定义的,则通过如下方法获取行列数

cout << sizeof(a)/sizeof(a[0]) << endl;  //行数outpuut 15
cout << sizeof(a[0]) / sizeof(a[0][0]) << endl; //列数outpuut 8

 
 

用vector构造自动扩容的二维数组的更多相关文章

  1. 【C语言】构造长度可变的二维数组

    #include <stdio.h> #include <malloc.h> #include <memory.h> int getArray(int ***p,i ...

  2. 使用vector<vector<int>>实现的一个二维数组

    本文为大大维原创,最早于博客园发表,转载请注明出处!!! 1 #include<iostream> #include<vector> using namespace std; ...

  3. 怎么使用C++标准库来实现二维数组

    在编程里,像界面布局是二维的,那么常常使用二维数组来表示界面的元素,那么就需要使用二维的数组,在现在C++肯定是以标准库为基础了,不再使用C的二维数组,那么怎么样做呢?下面就使用vector来实现二维 ...

  4. 【剑指offer】04A二维数组中的查找,C++实现

    1.题目 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数数组和一个整数,判断数组中是否含有该整数. 2.思路 首先选取数 ...

  5. C语言数组篇(四)二维数组

      二维数组声明: ][] ={{,,},{,,}; //两行 三列         二维数组在声明的时候可以不写行,但一定要写列 ] = {{,},{,,},{}}; //未声明的地方自动补零 二维 ...

  6. 剑指offer1: 组类型——二维数组中的查找(给定一个数字,查找是否在该数组中)

    1. 思路: 缩小范围 2. 方法: (1)要查找的数字等于数组中的数字,结束查找过程: (2)要查找的数字小于数组中的数字,去除该数字右边的数字,在剩下的数字里查找: (3)要查找的数字大于数组中的 ...

  7. c++中创建二维数组的几种方法

    一.用new申请内存空间 int **dp=new int*[n];//动态申请二维数组nxm ;i<n;++i){ dp[i]=new int[m]; } 二.用malloc申请内存空间 ; ...

  8. C++学习笔记之由文本文件读取数据到vector模板建立的二维数组 并存储为新的文本文件

    阅读本文可首先参考: C++学习笔记之输入.输出和文件 测试数据: /*读取txt文件到二维数组*/ #include <iostream> #include <fstream> ...

  9. stl vector创建二维数组

    vector<vector<); for (auto it = v.begin(); it != v.end(); it++) { ; (*it).reserve();//预留空间为5,但 ...

随机推荐

  1. pip换国内源

    pip换国内源 1.国内常用源   阿里云 http://mirrors.aliyun.com/pypi/simple/   中国科技大学 https://pypi.mirrors.ustc.edu. ...

  2. jqgrid 加按钮列

    1.在jqgrid表格中增加列,内容是图标,定义图标单击事件,可以操作这一行的数据,如下图 2.前台代码 <div id="grid_List"> <table ...

  3. js对象成员的访问

    var obj={0:1,1:'id'};//访问对象 obj['0'];//用[]来访问,不要用.的方式访问 -----对象与字符串的转换----- node.js JS对象和JSON字符串之间的转 ...

  4. laravel中,提交表单后给出提示例如添加成功,添加失败等等

    laravel中的表单插入,我想在表单插入成功后,可以像thinkphp一样可以有一个提示内容,上网Google,他们还是给出的方法就是 return redirect('/')->with(' ...

  5. SET IDENTITY_INSERT <Table Name> ON/OFF 转载

    This command is from SQL Server.  This command is to enable the users to set their own value for IDE ...

  6. poj1860--Currency Exchange

    Bellman-ford算法的反向应用--正循环检查 /** \brief poj 1860 Bellman-Ford * * \param date 2014/7/24 * \param state ...

  7. Atitit.ati  str  字符串增强api

    Atitit.ati  str  字符串增强api 1. java StringUtils方法全览 分类: Java2011-11-30 17:22 8194人阅读 评论(2) 收藏 举报 javas ...

  8. 自定义闹钟 Reminder

    Reminder reminder = ScheduledActionService.Find("MY REMINDER") as Reminder; if ( reminder ...

  9. [Egret]长按截屏分享、分享截屏图片、本地存储

    egret 分享有API可以把一个显示对象树渲染成一个位图纹理,我把它赋值给 HTML 的 Image 元素,就实现了图片的显示,在微信中,通过长按图片可以分享出去.当然在其他浏览器可以保存在本地. ...

  10. [转]C++ error C2011: “XXX”:“class”类型重定义

    http://blog.csdn.net/m_leonwang/article/details/27678219 尝试修复这个程序的错误: 点击下载源代码文件夹