In this section, we will see what is the at a () function in C++. The at() function is used to access the character at a given position.
In this program, we will iterate through each character using at a () function and print them into different lines.
Example Code
#include<iostream>
using namespace std;
main() {
string my_str = "Hello World";
for(int i = 0; i<my_str.length(); i++) {
cout << my_str.at(i) << endl; //get character at position i
}
}Output
H e l l o W o r l d