Sunday, December 11, 2016

3 different ways to loop through every char in a string in c++

When programming sometimes we need to loop through a string and deal with every character in that string. In c++ there are several ways to do that. In this post lets see 3 different ways to loop through a string.
  1. Using a range-based for loop (This feature is available from c++ 11)


  2. Using ierators


  3. Using normal for loop



If you have a null terminated character array this method also can be used.

Those are the 4 different ways that can be used to loop through strings. If you have suggestions or new methods pleas leave a comment below.

No comments:

Post a Comment

Optimize you working enviorenment : Single command to create & move to a directory in linux (C Shell, Bash)

Usually move to a directory just after creating is bit of a anxious task specially if the directory name is too long. mkdir long-name-of...