第十八章 21string数组与函数

// 21string数组与函数
/*
#include <iostream>
#include <string>
//假如要传递多个字符串,那么可以声明一个string对像数组,然后将数组传递到函数中
using namespace std;
void show(const string str[], int l);
int main()
{
	const int l = 5;
	string st[l];
	for(int i=0; i<l; i++)
	{
	    cout<<i<<"请输入:"<<endl;
		cin>>st[i];
	}
	show(st,l);
    return 0;
	//string对像数组与二级char型数组差不多,如:
	//string str[5]
	//char str[5][]
	//不同的是,string对像数组有自动调节数组大小的功能,而二级的char型数组却没有,因此使用二维char型数组你必须将数组定义得足够大,以避免数组越界
}
void show(const string str[], int l)
{
	for(int i=0; i<l; i++)
	{
	    cout<<i<<":"<<str[i]<<endl;
	}
}*/

  

posted @ 2012-09-24 22:26  简单--生活  阅读(221)  评论(0编辑  收藏  举报
简单--生活(CSDN)