Yeah, it's for.
And I know how to use STL. Really nice.
But I can't use it in school, because my school uses VS 6.0. I believe that came out almost two decades ago. Before the age of STL.
And my point is that cout/cin are easier than printf/scanf (though printf has a few advantages like formatted output...), my school teaches stdio.h and its C functions.
You know that I know how to use <vector>, don't you? Dx I'm not that bad at programming...
First off, I assume nothing.
The formatted output that printf can do can also be done with streams, via
stream manipulators.Back to that code segment, now.
for(int i = 5; i == 5;)
;
cout << i;
Unfortunately, the behavior of this code depends on the standard being used. Since you're using VS 6.0, your compiler is using the old (non-ISO) standard, which allows variables defined within for-loops to be referenced outside of the for-loop. So, the code initializes i to 5, and runs through the body of the for-loop. There is only a semicolon, which means the body does absolutely nothing, so the condition for the for-loop is checked. Since i == 5, the loop exits, and the value of i is printed to standard output.
If you were using a standards-compliant compiler, you'd get something a bit different:
$ g++ -o test test.cpp
test.cpp: In function ‘int main()’:
test.cpp:7:11: error: name lookup of ‘i’ changed for ISO ‘for’ scoping [-fpermissive]
cout << i << endl;
^
test.cpp:7:11: note: (if you use ‘-fpermissive’ G++ will accept your code)