C++ String相关函数

[b]构造函数(Constructors)[/b]
语法:
string();
string( size_type length, char ch );
string( const char *str );
string( const char *str, size_type length );
string( string &str, size_type index, size_type length );
string( input_iterator start, input_iterator end );


字符串的构造函数创建一个新字符串,包括:

以length为长度的ch的拷贝(即length个ch)
以str为初值 (长度任意),
以index为索引开始的子串,长度为length, 或者
以从start到end的元素为初值.
例如,

string str1( 5, 'c' );
string str2( "Now is the time..." );
string str3( str2, 11, 4 );
cout << str1 << endl;
cout << str2 << endl;
cout << str3 << endl;

显示

ccccc
Now is the time...
time

--------------------------------------------------------------------------------
[b]
操作符(Operators)[/b]
语法:
==
>
<
>=
<=
!=
+
+=
[]


你可以用 ==, >, <, >=, <=, and, != 比较字符串. 可以用 + 或者 += 操作符连接两个字符串, 并且可以用[]获取特定的字符.

相关主题:
at(), compare().
--------------------------------------------------------------------------------

[b]添加文本(append)[/b]
语法:
basic_string &append( const basic_string &str );
basic_string &append( const char *str );
basic_string &append( const basic_string &str, size_type index, size_type len );
basic_string &append( const char *str, size_type num );
basic_string &append( size_type num, char ch );
basic_string &append( input_iterator start, input_iterator end );

append() 函数可以完成以下工作:

在字符串的末尾添加str,
在字符串的末尾添加str的子串,子串以index索引开始,长度为len
在字符串的末尾添加str中的num个字符,
在字符串的末尾添加num个字符ch,
在字符串的末尾添加以迭代器start和end表示的字符序列.
例如以下代码:

string str = "Hello World";
str.append( 10, '!' );
cout << str << endl;

显示

Hello World!!!!!!!!!!

相关主题:
+ 操作符
--------------------------------------------------------------------------------

[b]赋值(assign)[/b]
语法:
basic_string &assign( const basic_string &str );
basic_string &assign( const char *str );
basic_string &assign( const char *str, size_type num );
basic_string &assign( const basic_string &str, size_type index, size_type len );
basic_string &assign( size_type num, char ch );


函数以下列方式赋值:

用str为字符串赋值,
用str的开始num个字符为字符串赋值,
用str的子串为字符串赋值,子串以index索引开始,长度为len
用num个字符ch为字符串赋值.
例如以下代码:

string str1, str2 = "War and Peace";
str1.assign( str2, 4, 3 );
cout << str1 << endl;

显示

and


--------------------------------------------------------------------------------

[b]at[/b]
语法:
reference at( size_type index );


at()函数返回一个引用,指向在index位置的字符. 如果index不在字符串范围内, at() 将报告"out of range"错误,并抛出out_of_range异常。 比如下列代码:

string text = "ABCDEF";
char ch = text.at( 2 );

显示字符 'C'.

相关主题:
[]操作符
--------------------------------------------------------------------------------

[b]begin[/b]
语法:
iterator begin();


begin()函数返回一个迭代器,指向字符串的第一个元素.

相关主题:
end()
--------------------------------------------------------------------------------

[b]c_str[/b]
语法:
const char *c_str();


c_str()函数返回一个指向正规C字符串的指针, 内容与本字符串相同.

相关主题:
[] 操作符
--------------------------------------------------------------------------------

[b]容量(capacity)[/b]
语法:
size_type capacity();


capacity()函数返回在重新申请更多的空间前字符串可以容纳的字符数. 这个数字至少与 size()一样大.

相关主题:
max_size(), reserve(), resize(), size(),
--------------------------------------------------------------------------------

[b]比较(compare)[/b]
语法:
int compare( const basic_string &str );
int compare( const char *str );
int compare( size_type index, size_type length, const basic_string &str );
int compare( size_type index, size_type length, const basic_string &str, size_type index2,
size_type length2 );
int compare( size_type index, size_type length, const char *str, size_type length2 );


compare()函数以多种方式比较本字符串和str,返回:

返回值 情况
小于零 this < str
零 this == str
大于零 this > str

不同的函数:

比较自己和str,
比较自己的子串和str,子串以index索引开始,长度为length
比较自己的子串和str的子串,其中index2和length2引用str,index和length引用自己
比较自己的子串和str的子串,其中str的子串以索引0开始,长度为length2,自己的子串以index开始,长度为length

相关主题:
操作符
--------------------------------------------------------------------------------

[b]拷贝(copy)[/b]
语法:
size_type copy( char *str, size_type num, size_type index );


copy()函数拷贝自己的num个字符到str中(从索引index开始)。返回值是拷贝的字符数


--------------------------------------------------------------------------------

[b]data[/b]
语法:
const char *data();


data()函数返回指向自己的第一个字符的指针.

相关主题:
c_str()
--------------------------------------------------------------------------------

[b]empty[/b]
语法:
bool empty();


如果字符串为空则empty()返回真(true),否则返回假(false).


--------------------------------------------------------------------------------

[b]end[/b]
语法:
iterator end();


end()函数返回一个迭代器,指向字符串的末尾(最后一个字符的下一个位置).

相关主题:
begin()
--------------------------------------------------------------------------------

[b]删除(erase)[/b]
语法:
iterator erase( iterator pos );
iterator erase( iterator start, iterator end );
basic_string &erase( size_type index = 0, size_type num = npos );


erase()函数可以:

删除pos指向的字符, 返回指向下一个字符的迭代器,
删除从start到end的所有字符, 返回一个迭代器,指向被删除的最后一个字符的下一个位置
删除从index索引开始的num个字符, 返回*this.
参数index 和 num 有默认值, 这意味着erase()可以这样调用:只带有index以删除index后的所有字符,或者不带有任何参数以删除所有字符. 例如:

string s("So, you like donuts, eh? Well, have all the donuts in the world!");
cout << "The original string is '" << s << "'" << endl;

s.erase( 50, 14 );
cout << "Now the string is '" << s << "'" << endl;

s.erase( 24 );
cout << "Now the string is '" << s << "'" << endl;

s.erase();
cout << "Now the string is '" << s << "'" << endl;

将显示

The original string is 'So, you like donuts, eh? Well, have all the donuts in the world!'
Now the string is 'So, you like donuts, eh? Well, have all the donuts'
Now the string is 'So, you like donuts, eh?'
Now the string is ''


--------------------------------------------------------------------------------

[b]查找(find)[/b]
语法:
size_type find( const basic_string &str, size_type index );
size_type find( const char *str, size_type index );
size_type find( const char *str, size_type index, size_type length );
size_type find( char ch, size_type index );


find()函数:

返回str在字符串中第一次出现的位置(从index开始查找)。如果没找到则返回string::npos,
返回str在字符串中第一次出现的位置(从index开始查找,长度为length)。如果没找到就返回string::npos,
返回字符ch在字符串中第一次出现的位置(从index开始查找)。如果没找到就返回string::npos
例如,

string str1( "Alpha Beta Gamma Delta" );
unsigned int loc = str1.find( "Omega", 0 );
if( loc != string::npos )
cout << "Found Omega at " << loc << endl;
else
cout << "Didn't find Omega" << endl;



--------------------------------------------------------------------------------

[b]find_first_of[/b]
语法:
size_type find_first_of( const basic_string &str, size_type index = 0 );
size_type find_first_of( const char *str, size_type index = 0 );
size_type find_first_of( const char *str, size_type index, size_type num );
size_type find_first_of( char ch, size_type index = 0 );


find_first_of()函数:

查找在字符串中第一个与str中的某个字符匹配的字符,返回它的位置。搜索从index开始,如果没找到就返回string::npos
查找在字符串中第一个与str中的某个字符匹配的字符,返回它的位置。搜索从index开始,最多搜索num个字符。如果没找到就返回string::npos,
查找在字符串中第一个与ch匹配的字符,返回它的位置。搜索从index开始。

相关主题:
find()
--------------------------------------------------------------------------------

[b]find_first_not_of[/b]
语法:
size_type find_first_not_of( const basic_string &str, size_type index = 0 );
size_type find_first_not_of( const char *str, size_type index = 0 );
size_type find_first_not_of( const char *str, size_type index, size_type num );
size_type find_first_not_of( char ch, size_type index = 0 );


find_first_not_of()函数:

在字符串中查找第一个与str中的字符都不匹配的字符,返回它的位置。搜索从index开始。如果没找到就返回string::nops
在字符串中查找第一个与str中的字符都不匹配的字符,返回它的位置。搜索从index开始,最多查找num个字符。如果没找到就返回string::nops
在字符串中查找第一个与ch不匹配的字符,返回它的位置。搜索从index开始。如果没找到就返回string::nops

相关主题:
find()
--------------------------------------------------------------------------------

[b]find_last_of[/b]
语法:
size_type find_last_of( const basic_string &str, size_type index = npos );
size_type find_last_of( const char *str, size_type index = npos );
size_type find_last_of( const char *str, size_type index, size_type num );
size_type find_last_of( char ch, size_type index = npos );


find_last_of()函数:

在字符串中查找最后一个与str中的某个字符匹配的字符,返回它的位置。搜索从index开始。如果没找到就返回string::nops
在字符串中查找最后一个与str中的某个字符匹配的字符,返回它的位置。搜索从index开始,最多搜索num个字符。如果没找到就返回string::nops
在字符串中查找最后一个与ch匹配的字符,返回它的位置。搜索从index开始。如果没找到就返回string::nops

相关主题:
find()
--------------------------------------------------------------------------------

[b]find_last_not_of[/b]
语法:
size_type find_last_not_of( const basic_string &str, size_type index = npos );
size_type find_last_not_of( const char *str, size_type index = npos);
size_type find_last_not_of( const char *str, size_type index, size_type num );
size_type find_last_not_of( char ch, size_type index = npos );


find_last_not_of()函数:

在字符串中查找最后一个与str中的字符都不匹配的字符,返回它的位置。搜索从index开始。如果没找到就返回string::nops
在字符串中查找最后一个与str中的字符都不匹配的字符,返回它的位置。搜索从index开始,最多查找num个字符如果没找到就返回string::nops
在字符串中查找最后一个与ch不匹配的字符,返回它的位置。搜索从index开始。如果没找到就返回string::nops

相关主题:
find()
--------------------------------------------------------------------------------

[b]get_allocator[/b]
语法:
allocator_type get_allocator();


get_allocator()函数返回本字符串的配置器.


--------------------------------------------------------------------------------

[b]插入(insert)[/b]
语法:
iterator insert( iterator i, const char &ch );
basic_string &insert( size_type index, const basic_string &str );
basic_string &insert( size_type index, const char *str );
basic_string &insert( size_type index1, const basic_string &str, size_type index2, size_type num );
basic_string &insert( size_type index, const char *str, size_type num );
basic_string &insert( size_type index, size_type num, char ch );
void insert( iterator i, size_type num, const char &ch );
void insert( iterator i, iterator start, iterator end );


insert()函数的功能非常多:

在迭代器i表示的位置前面插入一个字符ch,
在字符串的位置index插入字符串str,
在字符串的位置index插入字符串str的子串(从index2开始,长num个字符),
在字符串的位置index插入字符串str的num个字符,
在字符串的位置index插入num个字符ch的拷贝,
在迭代器i表示的位置前面插入num个字符ch的拷贝,
在迭代器i表示的位置前面插入一段字符,从start开始,以end结束.

相关主题:
replace()
--------------------------------------------------------------------------------

[b]长度(length)[/b]
语法:
size_type length();


length()函数返回字符串的长度. 这个数字应该和size()返回的数字相同.

相关主题:
size()
--------------------------------------------------------------------------------

[b]max_size[/b]
语法:
size_type max_size();


max_size()函数返回字符串能保存的最大字符数。


--------------------------------------------------------------------------------

[b]rbegin[/b]
语法:
const reverse_iterator rbegin();


rbegin()返回一个逆向迭代器,指向字符串的最后一个字符。

相关主题:
rend()
--------------------------------------------------------------------------------

[b]rend[/b]
语法:
const reverse_iterator rend();


rend()函数返回一个逆向迭代器,指向字符串的开头(第一个字符的前一个位置)。

相关主题:
rbegin()
--------------------------------------------------------------------------------

[b]替换(replace)[/b]
语法:
basic_string &replace( size_type index, size_type num, const basic_string &str );
basic_string &replace( size_type index1, size_type num1, const basic_string &str, size_type index2,
size_type num2 );
basic_string &replace( size_type index, size_type num, const char *str );
basic_string &replace( size_type index, size_type num1, const char *str, size_type num2 );
basic_string &replace( size_type index, size_type num1, size_type num2, char ch );
basic_string &replace( iterator start, iterator end, const basic_string &str );
basic_string &replace( iterator start, iterator end, const char *str );
basic_string &replace( iterator start, iterator end, const char *str, size_type num );
basic_string &replace( iterator start, iterator end, size_type num, char ch );


replace()函数:

用str中的num个字符替换本字符串中的字符,从index开始
用str中的num2个字符(从index2开始)替换本字符串中的字符,从index1开始,最多num1个字符
用str中的num个字符(从index开始)替换本字符串中的字符
用str中的num2个字符(从index2开始)替换本字符串中的字符,从index1开始,num1个字符
用num2个ch字符替换本字符串中的字符,从index开始
用str中的字符替换本字符串中的字符,迭代器start和end指示范围
用str中的num个字符替换本字符串中的内容,迭代器start和end指示范围,
用num个ch字符替换本字符串中的内容,迭代器start和end指示范围.
例如,以下代码显示字符串"They say he carved it himself...find your soul-mate, Homer."
string s = "They say he carved it himself...from a BIGGER spoon";
string s2 = "find your soul-mate, Homer.";

s.replace( 32, s2.length(), s2 );

cout << s << endl;

相关主题:
insert()
--------------------------------------------------------------------------------

[b]保留空间(reserve)[/b]
语法:
void reserve( size_type num );


reserve()函数设置本字符串的capacity 以保留num个字符空间。

相关主题:
capacity()
--------------------------------------------------------------------------------

resize
语法:
void resize( size_type num );
void resize( size_type num, char ch );


resize()函数改变本字符串的大小到num, 新空间的内容不确定。也可以指定用ch填充。


--------------------------------------------------------------------------------

[b]rfind[/b]
语法:
size_type rfind( const basic_string &str, size_type index );
size_type rfind( const char *str, size_type index );
size_type rfind( const char *str, size_type index, size_type num );
size_type rfind( char ch, size_type index );


rfind()函数:

返回最后一个与str中的某个字符匹配的字符,从index开始查找。如果没找到就返回string::npos
返回最后一个与str中的某个字符匹配的字符,从index开始查找,最多查找num个字符。如果没找到就返回string::npos
返回最后一个与ch匹配的字符,从index开始查找。如果没找到就返回string::npos
例如,在下列代码中第一次调用rfind()返回string::npos,因为目标词语不在开始的8个字符中。然而,第二次调用返回9,因为目标词语在开始的20个字符之中。
int loc;
string s = "My cat's breath smells like cat food.";

loc = s.rfind( "breath", 8 );
cout << "The word breath is at index " << loc << endl;

loc = s.rfind( "breath", 20 );
cout << "The word breath is at index " << loc << endl;

相关主题:
find()
--------------------------------------------------------------------------------

[b]size[/b]
语法:
size_type size();


size()函数返回字符串中现在拥有的字符数。

相关主题:
length(), max_size()
--------------------------------------------------------------------------------

[b]substr[/b]
语法:
basic_string substr( size_type index, size_type num = npos );


substr()返回本字符串的一个子串,从index开始,长num个字符。如果没有指定,将是默认值 string::npos。这样,substr()函数将简单的返回从index开始的剩余的字符串。

例如:

string s("What we have here is a failure to communicate");

string sub = s.substr(21);

cout << "The original string is " << s << endl;
cout << "The substring is " << sub << endl;

显示:

The original string is What we have here is a failure to communicate
The substring is a failure to communicate


--------------------------------------------------------------------------------

[b]交换(swap)[/b]
语法:
void swap( basic_string &str );


swap()函数把str和本字符串交换。例如:

string first( "This comes first" );
string second( "And this is second" );
first.swap( second );
cout << first << endl;
cout << second << endl;

显示:

And this is second
This comes first
保姆级教程:在Windows/Mac上从零部署清华Kronos股票预测模型(含Qlib数据更新避坑指南) 本文提供了一份详细的指南,帮助用户在Windows和Mac系统上从零部署清华Kronos股票预测模型,包括环境配置、模型权重获取、Qlib数据更新避坑等关键步骤。特别针对国内用户遇到的网络问题和数据更新不及时提供了解决方案,适合量化投资和金融科技爱好者快速上手。 阅读详情

相关推荐

LLM and Embedding区别

LLM(大语言模型)和 Embedding(嵌入)是自然语言处理(NLP)中的两个核心概念,它们的核心区别在于。Embedding 计算向量。

u010674101的专栏 1875

C++ | string用法指南

本文主要介绍STL容器之一 ---- string,在学习C++的过程中,我们要将C++视为一个语言联邦(摘录于Effective C++ 条款一)。如何理解这句话呢,我们学习C++,可将其分为四个板块;分别为C、Object-Oriented C++(面向对象的C++)、Template C++(模板)、STL。本文就介绍STL中的string;

Nice_W的博客 2万+

ElementUI中的el-table解决宽度问题 - 根据内容自动撑开

在使用element-ui中,会发现表格组件el-table在未指定宽度情况下,会自动计算并给表格宽度赋值。但实际开发中,有时需要根据内容实际长度自动撑开显示,由内容的多少而决定表格的宽度,而不是默认宽度为100%。在默认情况下表格宽度为100%显示,并且列项未指定宽度情况下,剩余部分会平均分配宽度,本案例实际需求是由内容自动撑开显示。componentUpdated

觉醒法师的专栏 1万+

C++ 字符串(string)常用操作总结

目录 1、定义一个字符串 2、读写 string 操作 3、查询字符串信息、索引 4、拼接、比较等操作 5、cctype 头文件 6、for 循环遍历 7、修改 string 的操作 8、string 搜索操作 9、数值转换 由单引号括起来的一个字符被称作 char 型字面值,双引号括起来的零个或多个字符则构成字符串型字面值。字符串字面值的类型实际上就是由常量字符构成的数组,,编译器在每一个字符串后面添加一个空字符('\0'),因此字符串的实际长度要比他的内容多1。 如字面值 'A'

Flag_ing的博客 4万+

Unity物理驱动3D汽车实现:从刚体控制到参数调优

在游戏开发中,刚体物理是实现真实物体运动与交互的核心技术。通过Unity的物理引擎,开发者可以模拟重力、碰撞、摩擦力等物理行为,为游戏世界注入真实感。其技术价值在于能够以符合物理规律的方式驱动游戏对象,避免穿墙、无视惯性等问题,从而提升游戏体验的真实性和沉浸感。这一原理广泛应用于角色控制、车辆模拟、物体破坏等场景。本文以3D小汽车为例,详细解析了如何通过Rigidbody组件施加力与扭矩,并利用C#脚本实现玩家输入逻辑,完成一辆可操控、能碰撞的物理驱动汽车。文中重点探讨了AddForce与角速度控制两种方案

weixin_34380948的博客 501

Vanna 2.0:基于LLM的智能文本到SQL框架,实现企业级数据查询与权限控制

文本到SQL技术是自然语言处理与数据库交互的重要桥梁,它允许用户使用日常语言直接查询数据库,无需编写复杂的SQL语句。其核心原理是利用大语言模型理解用户意图,并结合检索增强生成技术,将自然语言问题转换为准确的结构化查询语言。这项技术的价值在于大幅降低了数据访问门槛,提升了业务人员的数据自助分析能力,并能在金融分析、销售报表、运营监控等场景中实现实时数据洞察。Vanna 2.0作为一个开源框架,通过引入用户感知的智能体架构和行级安全策略,解决了企业级应用中的多租户数据隔离与权限控制等关键问题,使得自然语言数据

weixin_42629522的博客 546

【C++】string类的基础操作

C++中的string类是一个用于处理字符串的标准库类。 今天我们来学习在C++中string类的常见用法,比如构造、容量操作、遍历访问以及一些修改操作。

qq_64818885的博客 2912

深入Netflix影片分类数据抓取的Python爬虫实战:反反爬机制绕过与Playwright应用全解析

技术工具用途Playwright控制真实浏览器模拟用户行为开发语言asyncio异步调度浏览器任务pandas数据处理和导出sqlite3本地数据库存储支持随机UA模拟,增强反爬能力为什么选择 Playwright?✅ 支持多浏览器(Chromium、Firefox、WebKit)✅ 原生支持 Python 异步编程✅ 提供截图、滚动模拟、验证码处理等高级功能✅ 反爬能力强,模拟真实用户访问。

2201_76125261的博客 1239

string篇

string本质使一个类,类内封装了char *(字符串指针) 构造函数原型: string(); //空字符串 string(const char* s); //通过字符串初始化 string(const string& str); //(构造函数)通过string对象实例化另一个string对象 string(int n,char c); //使用n个字符初始化 赋值重载函数 = assign string& operator=(const...

wa的一声就哭了 1579

【数据集】全球首个10米分辨率精细分类土地覆盖数据集GLC_FCS10

【数据集】全球首个10米分辨率精细分类土地覆盖数据集GLC_FCS10

WW、forever的博客 1567

2025机械考研复试面试问题汇总篇(含13门科目),考研机械复试专业面试常见重点问题总结!考研机械复试专业面试准备看这一篇就够了!

(完整版内容:)1.汇集了本科各科的重点知识及多个机械名校800多个常见问题,共8.7万字185页,涵盖机械所以专业课的重点知识和常见问答。 2.涉及机械大类重点科目,包括:材料力学、控制工程、数控技术、机械制造技术基础、理论力学、液压传动、机械设计、机械原理、工程材料、互换性与技术测量、测试技术、汽车理论、程序设计与C语言等13门必修课。

weixin_56510835的博客 1862

【C++】string类的相关成员函数以及string的模拟实现

主要介绍了string类中常见的接口,以及相关的成员函数的模拟实现

jhj9201633的博客 871

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

C++中string类相关函数总结

转载自链接: link.

upUpUP-ls的博客 187

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

C++语言string类的相关函数

C++语言string类的相关函数 一、string的长度、容量 返回字符串对象的长度 1. size() 2. length() 返回已经分配给字符串对象的长度(容量) 3. capacity() 返回字符串能够存储的最大长度的字节数 4. max_size() string str("Test string"); cout<<str.size(); cout<<str.length(); cout<<str.capacity(); cout<<str.ma

m2426675454的博客 368

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

【C++】深入理解string相关函数:实现和分析

C++ 提供了强大的文本处理和数值转换功能组件,为程序员高效开发提供了便利工具,例如 std::stoi、std::stol、std::stod,以及实现反向操作的 std::to_string。这些函数在处理字符串与数值之间的转换时,表现出高度的灵活性和高效性。 本文将全面解析 C++ 中这些 string 相关的工具函数,包括它们的原理、用法、应用场景,以及必要的拓展内容,以帮助读者更好地掌握这些函数的使用,并在实际开发中灵活运用。 2025.1.12-✍88min

禅宗里有一个词叫做“因缘和合”。 所谓因缘,是指事件要发生所必须的条件。因缘和合就是当你聚集了这件事的一切条件,它就会自然而然的发生。“它就会自然而然的发生”,这种朴素而坚定的价值观让我们感到无比安心,安心到可以不用有任何担心焦虑。 1629

C++ String 相关函数

C++ String函数类

wjlwangluo的博客 1422

C++中string相关函数

C++ strings(字符串)构造函数(Constructors)语法:string();string( size_type length, char ch );string( const char *str );string( const char *str, size_type length );string( string &str, size_type index

DNCD 5926

C++ string类相关函数

1、简介   string 类是 STL 中 basic_string 模板实例化得到的模板类。其定义如下: typedef basic_string <char> string;   basic_string 此处可以不必深究。   string 类的成员函数有很多,同一个名字的函数也常会有五六个重载的版本。这里仅对常用成员函数按功能进行分类,并直接给出应用的例子,通过例子,可以基本掌握这些成员函数的用法。 2、函数 2.1 构造函数   string 类有多个构造函数,用法示例如下: st

小小何先生的学习之旅 3311

C++-string字符串相关函数与应用

C+±string字符串相关函数与应用

qq_37184702的博客 206

C++中string相关函数 操作

C++中string相关函数  C++ Strings(字符串)  -------------------------------------------------------------------------------- 构造函数(Constructors) 语法:  string(); string( size_type length, char ch ); str

yaokang522的专栏 3436

C++ string 相关的函数

蒟蒻介绍的string相关的函数,支持一下,点个关注吧

一只小蒟蒻的博客 896

c++ string相关函数

此篇持续更新loading... append 直接添加另一个完整的字符串: 如str1.append(str2); 添加另一个字符串的某一段子串: to_string toString()方法;数值、字符串、对象、布尔;都有toString方法;这个方法唯一能做的就是返回相应的字符串;其中null和undefined没有toString()方法; #include &lt;bit...

老痒的农舍 508

C++之String的常见用法与字符相关函数

C++的STL标准模板库提供的字符串类,用于处理字符串相关的问题。

生活·代码_这里是青_分享快乐 795

c++string类中相关函数

`replace(size_t pos, size_t len, const string& str)`:替换从`pos`开始的`len`个字符为`str`。- `string(size_t n, char c)`:创建一个由`n`个字符`c`组成的字符串。- `append(size_t n, char c)`:在当前字符串的末尾追加`n`个字符`c`。- `assign(size_t n, char c)`:将`n`个字符`c`赋值给当前字符串。

2302_81229447的博客 456
上一篇: C++ Map小结
下一篇: 8. cocos2dx Label换行(中文)
Hel1C
博客等级 码龄17年 6粉丝 106原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值