c++ access string by index code example
Example 1: indexing strings in c++
// string::operator[]
#include <iostream>
#include <string>
int main ()
{
std::string str ("Test string");
for (int i=0; i<str.length(); ++i)
{
std::cout << str[i];
}
return 0;
}
Example 2: how to access the element of string in c++
string myString = "Hello";
cout << myString[0];
// Outputs H