由于多种原因,该方案没有汇编成册。 你们要么使用一个极其古老的汇编者,一个极其宽容的汇编者,要么没有向我们表明你实际上存在问题的方案。
From your comments it seems that you actually can compile it. I can only guess that you are using a very old compiler. Perhaps an old MS-DOS compiler (Zortech C++? Turbo C++?) since the getch
function is not generally a standard library function and doesn t do the right thing in the curses library anyway. It s probably an old BIOS-based function from the MS-DOS days.
The standard was changed awhile ago (over 10 years now) so that variable declarations in the parenthesized section of a for loop are local to that loop. It was once not actually the case that this was true.
I no longer have access to any compiler that s so old it doesn t handle things this way. I m surprised anybody does. Your program will not compile on my compiler.
本文是你汇编的方案文本,尽管它要求<代码>-lcurs选项链接:
#include <iostream>
#include <curses.h>
using ::std::cout;
using ::std::endl;
int main()
{
for(int i=1;i<=10;i++)
{
cout<<i<<endl;
}
getch();
return 0;
}
Notice how the offending cout << i;
statement is gone? That because it will not compile on a modern compiler.
现在,请你将方案编辑成<代码>cout << i;。
#include <iostream>
#include <curses.h>
int main()
{
using ::std::cout;
int i;
for (i = 1; i <= 10; i++)
{
cout << i <<
;
}
cout << "last: " << i <<
;
getch();
return 0;
}
This, of course, does print out last: 11
at the very end. This happens for a very obvious reason. What value does i
have to have in order for the i <= 10
test to fail? Why, any value greater than 10! And since i
is having one added to it every loop iteration, the first value i
has that has the property of being greater than 10 is 11.
lo格检测是在 lo顶端进行的,用来决定 lo余部分是否应当执行。 而这种增益则发生在 lo底处(尽管出现在<<>>for>上)。 因此,<代码>i将刊印10,然后加添1。 然后将测试(i <=10
),将发现11 <=10是假的,控制将在休息室后排在纸面上,last:11
将印制。
是的,在C也会发生同样的事情。