当前位置:网站首页>STL string output and modification
STL string output and modification
2022-07-19 13:42:00 【joker_ 0030】
1、string Output
#include <iostream>
using namespace std;
void StrCout()
{
string str2("ojkojkojk");
cout << str2 << endl;
cout << str2.c_str() << endl;
cout << str2[0] << endl;
cout << str2.at(3)<< endl;//at() Function returns a reference , Point at index The character of position ( Subscript ), If index Not within the string range ,at() Will report “out f range” error
// Cross the border
try
{
str2.at(19);
}
/*catch (...)
{
cout << " Across the border \n";
}*/
catch (out_of_range& a)
{
cout << " Across the border \n";
}
}
int main()
{
StrCout();
system("pause");
return 0;
}
2、
#include <iostream>
using namespace std;
void StrCout()
{
string str2("ojkojkojk");
cout << str2 << endl;
cout << str2.c_str() << endl;
cout << str2[0] << endl;
cout << str2.at(3) << endl;//at() Function returns a reference , Point at index The character of position ( Subscript ), If index Not within the string range ,at() Will report “out f range” error
// Cross the border
try
{
str2.at(19);
}
/*catch (...)
{
cout << " Across the border \n";
}*/
catch (out_of_range& a)
{
cout << " Across the border \n";
}
}
void StrChange()
{
string str2("ojkojkojk");// Change
/*str2[2] = 's';
str2.at(3) = 'q';// Replace */
//string str3(5, 'q');// increase
string str3("abcdefg");//insert function . Insert
//str2.insert(2, str3);// take str3 Insert the subscript as 2 The location of .
//str2.insert(2, "akfdsks");// Insert the string with the subscript 2 The location of .
//str2.insert(3, str3,0,2);// take str3 Subscript is [0,2) Insert str2 The subscript in is 3 The location of .
//str2.insert(3,"sjhdfja", 2);// Subscript the string as [0,2) Insert str2 The subscript in is 3 The location of .
//str2.insert(3, 2, 'b');// stay str2 The subscript of is 3 Insert at 2 individual b.
//str2 += str3;// Add... At the end .// increase
//str2 += "sjhasd";// Add... At the end .
//append function // Add... At the end , And insert The approximate , What is inserted is the end .// increase
//str2.append(str3);
//str2.append("sdhasjj",3);// The first three are added to str2 after
//str2.append(3,'w');// Will three w Add to str2 after
// Reassign // Change
//str2 = "qwer";
//str2 = str3;
//cin>>str2;
//str2.assign("ashjd", 2);// And insert and append The usage is the same .
// Delete
//str2.erase(2,3);// stay str2 From the subscript is 2 To delete 3 Characters .
str2.erase(0,str2.length());// Delete all characters .
cout << str2 << endl;
}
int main()
{
//StrCout();
StrChange();
system("pause");
return 0;
}
边栏推荐
- [7.14] code source - [open box] [XOR inverse] [continuous subsequence] [trigonometric fruit count]
- How to add a thread in MFC
- onvif协议相关:2.1.2 none方式获取截图url
- Forget about postman. Apifox is better
- codeforce:G. Good Key, Bad Key【贪心】
- Health prevention guide 3: health care
- Computer dial-up Internet access
- 统计直播间的榜一信息,从这里起步
- 【码蹄集新手村 600 题】计算一个整数有多少位数
- Elastic load balancing automatically distributes the access traffic to multiple cloud servers, expands the external service capacity of the application system, and improves the security of the applica
猜你喜欢

Responsive dream weaving template wine cellar website

【7.13】代码源 -【饿饿 饭饭】【路径计数2】【函数求和】
![Codeforce:a. difference operations [mathematical thinking]](/img/be/28bcb5dd8b9a36f2955f1912f289a3.png)
Codeforce:a. difference operations [mathematical thinking]

Some common operation commands of the command line and solutions to common errors

关于数据字典的一些解惑

onvif协议相关:2.1.3 none方式获取流地址
![[micro Service ~ advanced] configuration center practice](/img/6f/e365a93be7ed9cceafecf7c506965a.png)
[micro Service ~ advanced] configuration center practice
![[postgraduate entrance examination vocabulary training camp] day 7 - second, attract, current, collect, simple, communicate, vocation](/img/4e/79da9868930994fe6389b717efc4e9.png)
[postgraduate entrance examination vocabulary training camp] day 7 - second, attract, current, collect, simple, communicate, vocation

Flutter uses animatedswitcher to switch scenes
![[code hoof set novice village question 600] format specifier of float and double](/img/19/433f794617f3c3c72732f1a4efe252.png)
[code hoof set novice village question 600] format specifier of float and double
随机推荐
Flutter 使用 AnimatedSwitcher 做场景切换
【Acwing】第60场周赛 题解
How to upgrade Flink job gracefully?
"Podcast with relish" 392 original soup, original food: midsummer night, mashed horse, kebab, and pull board
[code shoe set novice village question 600] for the formatting control of strings, that is, the width and accuracy of strings
「技术播客月」Day 10: Meta Podcast: 聊聊播客这件事
[code hoof set novice village question 600] align left and right when outputting
【码蹄集新手村 600 题】科学计数法的实现方式,输出指数形式
【码蹄集新手村 600 题】如何使整数逆序
Helloword and led: a quick start to Hongmeng device development -- Huawei cloud 14 day Hongmeng device development practical learning notes Chapter 2
Codeforce:g. good key, bad key [greed]
Running node for getting started with eth
asterisk:No compatible codecs, not accepting this offer!
[7.14] code source - [open box] [XOR inverse] [continuous subsequence] [trigonometric fruit count]
名片管理的框架搭建
【南瓜书ML】(task2)线性模型的数学推导(最小二乘估计、广义瑞利商、极大似然估计等)
【动态规划】—— 最长上升子序列模型
Transphorm's surface mount packaging product series adds industry standard to-263 (D2Pak) packaging products to expand the advantages of supergan platform
忘掉Postman,Apifox更好用
统计直播间的榜一信息,从这里起步