string

本文通过一个C++程序示例展示了字符串的各种基本操作,包括连接、查找特定字符的位置及提取子串等。此外还介绍了如何使用标准库中的list容器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include "stdafx.h"
#include<string>
#include<list>
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
 string str("abc");
 str[0] ;
 cout << str[0] << endl;
 cout << str.c_str()<<endl;//输出abc
 string str2("123");
 str = str + str2;
 cout << str << endl;
 str = str + "esf" + "++";
 cout << str << endl;
 cout << "*******************************" << endl;

 int pos=str.find("_");//找到加号,并返回该加号的索引值,//如果没找到就返回-1,找到返回索引值
 cout << pos << endl;
 pos = str.find_first_not_of('+');//找第一个不是加号的,并返回索引值
 cout << pos << endl;
 pos = str.find_first_of('+');//找第一个是加号的,并返回索引值
 pos = str.find_last_not_of('+'); //找最后一个不是加号的,并返回索引值
 pos = str.find_first_of('+');//找最后一个是加号的,并返回索引值

 cout << "*****************************" << endl;
 //string strsub = str.substr(0,3);//获得【0,3)的子串
 string strsub = str.substr(3);//获得3到后面的子串
 cout << strsub << endl;
 cout << "*****************************" << endl;

 list<string>  strlist;//一个string类型的list容器
 return 0;
}

转载于:https://www.cnblogs.com/rong123/p/7727646.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值