C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C++ String front()This function is used to reference a first character of the string. Syntax
Consider a string str. Syntax would be: char& p = str.front(); Parameter
This function does not contain any parameter. Return valueIt is used to return a reference of the first character. Example 1
Let's see the simple example.
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str ="12345";
cout<<str.front();
return 0;
}
Output: 1 Example 2Let's see an another simple example.
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str ="javaTpoint";
cout<<str.front();
return 0;
}
Output: j Example 3Let's see a simple example to modify first character using front() function.
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str ="hello World";
str.front()='H';
cout<<str;
return 0;
}
Output: Hello World
Next TopicC++ Strings
|