C++实现二维字符串数组
最近有个需求,要利用c++实现一个二维的字符串数组,网上查了下,竟然没找到
因为c++的string用起来感觉非常繁琐,所以还是决定利用char型指针来做这个功能
思路是二维数组里存的都是一维数组,一维数组里存char*
所以解决方案如下:
const char* getContent(int row,int column){ const char* temp1[] = { "1行1列","1行2列","1行3列","1行4列","1行5列", }; const char* temp2[] = { "2行1列","2行2列","2行3列","2行4列","2行5列", }; const char* temp3[] = { "3行1列","3行2列","3行3列","3行4列","3行5列", }; const char* temp4[] = { "4行1列","4行2列","4行3列","4行4列","4行5列", }; const char* temp5[] = { "5行1列","5行2列","5行3列","5行4列","5行5列", }; const char** temp[] = { temp1,temp2,temp3,temp4,temp5, }; const char** tab =temp[row]; return tab[column]; }
这个功能很基础,但是自己也思索了好些时间并且重新查阅了指针相关,才想通了,只能说写出这部分代码让我对c++的指针的理解更深了一层
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: Mina学习之IoSession
- 下一篇: PHP缓存机制