C++ String front()
C++ String front()
此函数用于引用字符串的第一个字符。
语法
考虑字符串str。语法为:
参数
此函数不包含任何参数。
返回值
它用于返回第一个字符的引用。
示例1
让我们看一个简单的示例。
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str ="12345";
cout<<str.front();
return 0;
}
输出:
示例2
让我们看另一个简单的示例。
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str ="lidihuo";
cout<<str.front();
return 0;
}
输出:
示例3
让我们看一个使用front()函数修改第一个字符的简单示例。
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str ="hello World";
str.front()='H';
cout<<str;
return 0;
}
输出: