什么是C++字符串数组

sunwantc 2008-12-11 10:12:53
什么是C++字符串数组,最好举例说明,要有源码
...全文
363 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
wensheng_zh2007 2008-12-12
  • 打赏
  • 举报
回复
应该来说就是指的char[][]
bfhtian 2008-12-12
  • 打赏
  • 举报
回复

string str[]={"hello","world!"};
blackboycpp 2008-12-11
  • 打赏
  • 举报
回复

#include <iostream>
#include <string>
using namespace std;

int main()
{
string arrStr[3];

arrStr[0] = "aaaaa";
arrStr[1] = "bbbbb";
arrStr[2] = "ccccc";

for(int i=0; i<3; i++)
cout << arrStr[i] << endl;

cin.get();
return 0;
}
bbb332 2008-12-11
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 lann64 的回复:]
c++里用string类型
string s[5];// 字符串数组
s[0]=string("hello ");
s[1]=string("world!");
[/Quote]
up
lann64 2008-12-11
  • 打赏
  • 举报
回复
c++里用string类型
string s[5];// 字符串数组
s[0]=string("hello ");
s[1]=string("world!");
ChinaZhujia 2008-12-11
  • 打赏
  • 举报
回复
vector<string> str;
str.push_back("one");
str.push_back("two");
str.push_back("three");

这样str[0] = "one";
str[1] = "two";
ChinaZhujia 2008-12-11
  • 打赏
  • 举报
回复
vector<string> str;
str.push_back("one");
str.push_back("two");
str.push_back("three");

这样str[0] = "one";
str[1] = "two";
星羽 2008-12-11
  • 打赏
  • 举报
回复

// 字符串
char str[128];
strcpy(str, "hello world");

//字符串数组
char str_arry[4][128];
strcpy(str_arry[0], "hello world 0");
strcpy(str_arry[1], "hello world 1");
strcpy(str_arry[2], "hello world 2");
strcpy(str_arry[3], "hello world 3");
  • 打赏
  • 举报
回复
up了,我想如果知道数组,又知道字符串,应该不难理解字符串数组吧。
asksgp 2008-12-11
  • 打赏
  • 举报
回复
string person[3];
person[0]="man",person[1]="woman",person[2]="renyao";
ypb362148418 2008-12-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 CS_DN_Sniper 的回复:]
对于多个字符串的处理需用字符串数组描述,字符串数组相当于二维字符数组。
例如:
(1)100个城市名
char cityEl00][,16];/*假定城市名不超过16个字符*/
100个城市名分别用city[0]、city[1]、…、city[i]、…、city[99]描述,city[i]相当于一字符数组。
(2)1000本书名
char book[1000][30];/*假定书名不超过30个字符*/
1000本书名分别用book[O]、book[1]、…、book[i]、…、bo…
[/Quote]

//楼上的说的很有道理,例子也很典型,支持
三文鱼也会飞 2008-12-11
  • 打赏
  • 举报
回复
对于多个字符串的处理需用字符串数组描述,字符串数组相当于二维字符数组。
例如:
(1)100个城市名
char cityEl00][,16];/*假定城市名不超过16个字符*/
100个城市名分别用city[0]、city[1]、…、city[i]、…、city[99]描述,city[i]相当于一字符数组。
(2)1000本书名
char book[1000][30];/*假定书名不超过30个字符*/
1000本书名分别用book[O]、book[1]、…、book[i]、…、book[999]描述,book[i]相当于一字符数组。
下面举几个例子来认识字符数组及字符串的应用,中国自学编程网整理发布。
例用字符数组输出下面图案:
程序如下:
/*程序8—8,用字符数组输出图案*/
main()
{
static char ch[3][5]={\"***\",\"*****\",\"***\"};
puts(ch[O]);
printf(\"\\n\");
puts(chili);
printf(\'rkn”);
puts(ch[2]);
printf(\"\\n\");
}

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧