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++?
November 14-16, Berlin, Germany
November 18-23, Wrocław, Poland
November 25, Wrocław, Poland
February 10-15, Hagenberg, Austria
March 19-21, Madrid, Spain
April 1-4, Bristol, UK
June 16-21, Sofia, Bulgaria
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.