AFAIK, thats not standard C++. There is no 'for...each' construct in C++. Its C++/CLI .
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
well damn my compiler for giving me access to for each.
let's write a while statement then!
string foo = "super duper long string of wooorrrdddsss";
int c = 0;
while ( c < foo.length() )
{
cout << foo[c];
c++;
}
Computationally expensive. length() function is called each time the loop is executed. Why not something simple like:
int length = foo.length();
for(int i = 0; i < length; ++i)
cout << foo[i] << '\n';
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734