4 ms·
This is probably one of the better use cases for the comma operator in C. http://stackoverflow.com/questions/52550/what-does-the-operator-do-in-c http://stacko
by kqr2 15y ago
This is probably one of the better use cases for the comma operator in C.
http://stackoverflow.com/questions/52550/what-does-the-operator-do-in-c http://stackoverflow.com/questions/52550/what-does-the-opera...
string s;
while(read_string(s), s.len() > 5)
{
//do something
}
versus
string s;
read_string(s);
while(s.len() > 5)
{
//do something
read_string(s);
}
- tedunangst 15y agofor (read_string(s); s.len() > 5; read_string()) or just fix the damned read_string function to return the length read. [nevermind s.len() is unlikely to appear in C.]
- deleted 15y ago[deleted]
- steve-howard 15y agoSo is class string, so we're really talking about uses for the operator in C/C++. I'd say the for version is better if you can declare the variable in the initialization section (tighter scope), but the while version has you repeat yourself less if the variable's already there.
- alexk7 15y agoI find this easier to read: string s; for (;;) { read_string(s); if (s.len() <= 5) break; //do something }
- deleted 15y ago[deleted]