C++ std::string Looping through each character

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

C++11

std::string supports iterators, and so you can use a ranged based loop to iterate through each character:

std::string str = "Hello World!";
for (auto c : str)
    std::cout << c;

You can use a "traditional" for loop to loop through every character:

std::string str = "Hello World!";
for (std::size_t i = 0; i < str.length(); ++i)
    std::cout << str[i];


Got any C++ Question?