易网时代-编程资源站
Welcome
微信登录
编程资源
图片资源库
蚂蚁家优选
PDF转换器
软件资源
软件开发
、
小程序制作
、
系统集成与运维
、
空间租用
、
硬件开发
、
视频监控
、
技术咨询与支持
——联系电话:0311-88999002/88999003
首页
/
操作系统
/
Linux
/
String对象具有类似数组的行为
可以像处理数组那样来处理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: ";
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;
}
收藏该网址
版权所有©石家庄振强科技有限公司2024
冀ICP备08103738号-5
网站地图