Answers for "for char 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
4

index string c++

#include <string>
#include <iostream>

int main(){
  //index string by using brackets []
  std::string string = "Hello, World!";
  //assign variable to string index
  char stringindex = string[2];
  
}
Posted by: Guest on June-15-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

Browse Popular Code Answers by Language