#include#include using namespace std; int main () { string str = "Hello World!"; cout << "The character at index 4 is " << str.charAt(4) << endl; return 0; }
The character at index 4 is o
#include#include using namespace std; int main () { string str = "C++ is a powerful language!"; for (int i = 0; i < str.size(); i++) { if (str.charAt(i) == 'a') { cout << "The first 'a' is found at index " << i << endl; break; } } return 0; }
The first 'a' is found at index 5The charAt function is a built-in function in the C++ string library.