Quick A: for( char c : str )
.
Recently on StackOverflow:
Traversing a string in C++
I am looking for something similar to traversing a string in Python:
i.e.
for char in str: do somethingHow can I do this in C++?
March 18-23, Tokyo, Japan
April 17-20, Bristol, UK
April 24-26, Leganes, Spain
April 30, Online
May 7-12, Aspen, CO, USA
June 24-29, St. Louis, MO, USA
July 2-5, Folkestone, Kent, UK
By Blog Staff | Oct 31, 2014 01:42 AM | Tags: basics
Quick A: for( char c : str )
.
Recently on StackOverflow:
Traversing a string in C++
I am looking for something similar to traversing a string in Python:
i.e.
for char in str: do somethingHow can I do this in C++?
Hello Kitty said on Nov 2, 2014 11:41 AM:
for(unsigned int i = 0; i < str.length(); i++)
{
cout << str[i];
dostuff
}
for(auto i = str.cbegin(); i != str.cend(); i++)
{
cout << *i;
dostuff
}
for(auto i = str.begin(); i != str.end(); i++)
{
cout << *i;
dostuff
}
Arek Bal said on Nov 2, 2014 01:46 PM:
std::string s = "hello world";
for (auto c : s)
{
}
//or... in case u need to modify given chars
for (auto& c : s)
c = c + 1; // or whatever
Bayu Setiaji said on Nov 17, 2014 03:50 PM:
for(char& c:str)
// use c, without modifying given char
Add a Comment
Comments are closed.