Answers for "for 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
1

how to iterate throguh a string in c++

void print(const std::string &s)
{
    for (std::string::size_type i = 0; i < s.size(); i++) {
        std::cout << s[i] << ' ';
    }
}
Posted by: Guest on July-22-2020
0

c++ read each char of string

std::string str = ???;
for(std::string::iterator it = str.begin(); it != str.end(); ++it) {
    do_things_with(*it);
}
Posted by: Guest on November-12-2020

Code answers related to "for each character in string c++"

Browse Popular Code Answers by Language