Hi "The Brain"
can you explain this for
(int i=0, length=name.size(); i<length; i++)
please
i dont really understand it... especially <length=name.size(); i<length>
thank you
Printable View
Hi "The Brain"
can you explain this for
(int i=0, length=name.size(); i<length; i++)
please
i dont really understand it... especially <length=name.size(); i<length>
thank you
Code:
for (Initialization section ; Comparison/control/ending section ; Increment/Do every loop (usually related to the previous two sections) )
//You are not limited to one thing in each section though, you can have as many as you
//want in each section seperated by a comma
for (int i = 0, j = 1, k = 2; i < 10, j < 10; i++, j += 2, k--)
cout << i << " " << j << " " << k << endl;
//j<10 eval's false first so it stops then.
<in response to The Brain's surprise...>
Not to mention, the function islower() is usually implemented as a simple table lookup, rather than a conditional test. Secondly, the test:Quote:
Originally Posted by SlyMaelstrom
will evaluate true for nonalphabetic characters on an EBCDIC machine. Some of us work on those!Code:if ( 'a' <= name[i] && name[i] <= 'z' ) { ... }
Also, for more safety:
(note unsigned char parameter type) for the case where char is signed, and the implementation of std::islower is using the aforementioned table lookup. Due to sign extension in that case, the index for the table could end up negative, and would likely exceed the bounds of the table. Admittedly, a few stars have to align, and the moon must be in the seventh house, but it is possible.Code:struct is_lower {
int operator() ( unsigned char c )
{
return islower ( c );
}
};
hi, can this make it into funtion?