进程 中的 char& front()函数

首页 / C++入门教程 / 进程 中的 char& front()函数

此函数用于引用字符串的第一个字符。

front - 语法

char& p = str.front();

front - 返回值

它用于返回第一个字符的引用。

front - 例子1

让我们看一个简单的例子。

#include<iostream>
#include<string>
using namespace std;
int main()
{
	string str ="12345";
	cout<<str.front();
	return 0;
}

输出:

1

front - 例子2

让我们来看另一个简单的例子。

#include<iostream>
#include<string>
using namespace std;
int main()
{
	string str ="learnfk";
	cout<<str.front();
	return 0;
}

输出:

j

front - 例子3

让我们看一个简单的示例,使用front()函数修改第一个字符。

#include<iostream>
#include<string>
using namespace std;
int main()
{
	string str ="hello World";
	str.front()='H';	
	cout<<str;
	return 0;
}

输出:

Hello World

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

技术领导力实战笔记 -〔TGO鲲鹏会〕

程序员进阶攻略 -〔胡峰〕

Python核心技术与实战 -〔景霄〕

移动端自动化测试实战 -〔思寒〕

JavaScript核心原理解析 -〔周爱民〕

To B市场品牌实战课 -〔曹林〕

爱上跑步 -〔钱亮〕

编程高手必学的内存知识 -〔海纳〕

快手 · 移动端音视频开发实战 -〔展晓凯〕

好记忆不如烂笔头。留下您的足迹吧 :)