【资料备份】c++声明二维变长数组,并用memset赋予0值
2011-03-04 15:08
330 查看
示例代码
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string s1="123456";
string s2="abc";
int **count=new int*[s2.size()];
for (int i=0;i<s2.size();i++)
{
count[i]=new int[s1.size()];
memset(count[i],0,sizeof(int)*s1.size());
}
for (int i=0;i<s2.size();i++)
{
for (int j=0;j<s1.size();j++)
{
cout<<count[i][j]<<endl;
}
}
for (int i=0;i<s2.size();i++)
{
delete[]count[i];
}
delete []count;
cout<<"finish"<<endl;
int end;
cin>>end;
}
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string s1="123456";
string s2="abc";
int **count=new int*[s2.size()];
for (int i=0;i<s2.size();i++)
{
count[i]=new int[s1.size()];
memset(count[i],0,sizeof(int)*s1.size());
}
for (int i=0;i<s2.size();i++)
{
for (int j=0;j<s1.size();j++)
{
cout<<count[i][j]<<endl;
}
}
for (int i=0;i<s2.size();i++)
{
delete[]count[i];
}
delete []count;
cout<<"finish"<<endl;
int end;
cin>>end;
}
相关文章推荐
- c++ 依据输入动态声明数组(一维,二维)
- C++ L1-039. 古风排版(如何声明二维动态数组)
- c++声明并释放动态二维、三维数组
- c++ 根据输入动态声明数组(一维,二维)
- c++ 依据输入动态声明数组(一维,二维)
- c++ 根据输入动态声明数组(一维,二维)
- C++ 二维动态数组的声明与删除
- char*动态数组用c++ifstream和ofstream进行文件读写并用memset初始化
- C/C++二维数组的动态分配及参数传递
- 动态创建二维vector数组 C和C++ 及指针与引用的区别
- C++ 可以声明非常量大小的数组
- C++二维动态数组的创建与删除
- C/C++ 二维数据 静态动态声明和初始化及访问方法实例
- C++:二维数组初始化
- Java & C++ 数组声明和使用语法对比
- C++中二维动态数组的创建
- 二维动态数组的声明与传参
- C++动态分配二维/三维数组
- C/C++ 二维数据 静态动态声明和初始化及访问方法实例
- [原创]C/C++中复杂指针声明&&数组名的一点小事