1#include <string>
2#include <iostream>
3
4int main(){
5 //index string by using brackets []
6 std::string string = "Hello, World!";
7 //assign variable to string index
8 char stringindex = string[2];
9
10}
1// string::operator[]
2#include <iostream>
3#include <string>
4
5int main ()
6{
7 std::string str ("Test string");
8 for (int i=0; i<str.length(); ++i)
9 {
10 std::cout << str[i];
11 }
12 return 0;
13}