string对象具有类似数组的行为
2012-10-25 10:49
162 查看
可以像处理数组那样来处理String 对象!
// String.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include<iostream> #include<string> int main(int argc, char* argv[]) { using namespace std; string first_name , last_name; cout<<"Enter your first and last name:"; cin>>first_name >>last_name; cout<<endl<<endl; cout<<"your last name is spelled:\n"; int i ; for(i = 0; i < last_name.length() ; i++) //用for循环操纵数组 { cout<<last_name[i]<<" "; last_name[i] = '-'; } cout<<endl; for(i = 0; i < last_name.length() ; i++) { cout<<last_name[i]<<" ";//在每个字母下面显示一个"-" } cout<<endl; cout<<"Good day "<<first_name<<endl; return 0; }
相关文章推荐
- Java中利用MessageFormat对象实现类似C# string.Format方法格式化
- MessageFormat对象实现格式化字符串输出,类似C#中的string.format方法
- Java中利用MessageFormat对象实现类似C# string.Format方法格式化
- js Array.from 从类似数组 或者可迭代对象中返回数组
- OC学习之道:OC对象,字符串和数组的使用方法NSString,NSMutableString ,NSArray,NSMutableArray
- javascript 数组和对象的浅复制和深度复制 assign/slice/concat/JSON.parse(JSON.stringify())
- List数组对象 转到 String 数组当中
- android Parcelable 带有数组的对象如何序列化 String[] Long[] int[] Object[]
- [置顶] php超级预定数组( 类似javaWeb中域对象),函数,对象,进一步加深知识点
- 对string对象经行扩展,使其具有删除前后空格的方法
- Java中利用MessageFormat对象实现类似C# string.Format方法格式化
- ES6 学习笔记(一)String、数值、数组、对象
- Spring 框架下,用数组作为参数 传入到 存储过程,或存储过程返回动态数组到java程序 ,BLOB等大对象类似
- jQuery如何返回一个类数组对象,js让一个对象的行为像一个数组一样
- Java学习note 数组,String,面向对象综合
- 编写程序读入一组string类型的数据,并将它们存储在vector中,再将vector对象复制给一个字符指针数组。
- 将List<Object[]>数组对象转换成List<HashMap<String, Object>>集合对象
- 将具有length属性的对象转成数组
- ES6---for...of遍历‘类似’数组的数据结构,array set map string与iterator
- string对象代替char数组实现字符串的组合存储并显示