Answers for "loop through each character in string c++"

C++
1

loop through char in string c++

std::string s("Hello world");

for (char & c : s)
{
    std::cout << "One character: " << c << "\n";
    c = '*';
}
Posted by: Guest on May-23-2021
0

c++ loop through string

#include <iostream>

int main()
{
	std::string str = "Hello World";

	for(int i = 0; i < str.size(); i++)
	{
		std::cout << i << ". " << str.at(i) << std::endl;
	}

	return 0;
}
Posted by: Guest on February-20-2022

Code answers related to "loop through each character in string c++"

Browse Popular Code Answers by Language