C++字符串数组
来源:互联网 发布:山东广电网络集团官网 编辑:程序博客网 时间:2024/06/16 04:57
字符串数组的使用:
1. 字符串数组的定义: 指针 + 一维数组:const char* season[] = { "Spring", "Summer", "Fall", "Winter" }。season中每个元素都是一个指针。
2. 调用字符串数组中的每一个字符。season[0] = "Spring";
// chapter7.8.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>using namespace std;// 定义字符串数组(* array[], 指针加一维数组)const int num = 4;const char* season[num] = { "Spring", "summer", "Fall", "Winter" };struct Expense{double expense[num];};void fill_array(Expense& e, const int n) {for (int i = 0; i < n; i++) {// 字符串数组的使用, 如何调用字符串数组中的一个字符串cout << "Enter " << season[i] << " expense:" << endl;cin >> e.expense[i];}}void show_array(const Expense e, const int n) {for (int i = 0; i < n; i++) {cout << season[i] << ":\t";cout << e.expense[i] << endl;}}int _tmain(int argc, _TCHAR* argv[]) {Expense exp = { { 0 } };fill_array(exp, num);show_array(exp, num);return 0;}
// lesson5.20.cpp : Defines the entry point for the console application.// 二位数组的几种形式#include "stdafx.h"#include <iostream>using namespace std;const int Cities = 5;const int Years = 4;int _tmain(int argc, _TCHAR* argv[]) {// 字符串数组const char* cities[Cities] = {"Gribble City","Gribbletown","New Gribble","San Gribble","Gribble vista"};int maxTemperature[Years][Cities] = {{ 96, 100, 87, 101, 105 },{ 96, 98, 91, 107, 104 },{ 97, 101, 93, 108, 107 },{ 98, 103, 95, 109, 108 } };cout << "Maximum temperature for 2008-2011:" << endl;for (int i = 0; i < Cities; i++) {cout << cities[i] << ":\t";for (int j = 0; j < Years; j++) {cout << maxTemperature[j][i] << "\t";}cout << endl;}return 0;}
阅读全文
0 0
- C 字符串 数组
- C:数组与字符串
- C 字符串数组排序
- C数组和字符串
- c数组,字符串相加
- C数组与字符串
- 字符串,字符数组(c/c++)
- 关于C语言字符串数组
- C语言字符串、字符数组
- Objective-c 字符串 数组 转换
- objective c 字符串处理 ,数组
- C 字符数组和字符串
- C语言--数组与字符串
- c语言数组与字符串
- C语言之数组、字符串
- C语言------数组和字符串
- C语言 数组和字符串
- C语言之字符串,数组
- C++随记(一)---字符串数组的输入问题
- faster rcnn解析之stage1_rpn_solver60k80k.pt
- PHP面试之文件夹下内容重复的文件去重
- IO输出输入流
- NYOJ-353 3D地图搜索
- C++字符串数组
- 360浏览器下自动填写用户名密码惹祸了
- Count of Smaller Numbers After Self
- POJ2676
- SPOJ
- androidSudio学习网站
- 18、vue.js 之路由钩子函数
- 算法作业_24(2017.5.23第十四周)
- hdu1846(巴什博弈)