int表示不正确 [英] int representation incorrect
问题描述
我正在尝试使用for循环打印一个简单的int输出,并且
递增一个数字,例如
unsigned int count = 0 ;
for(int i = 0; i< 5; i ++){
cout<<计数<<结束;
}
我希望在下一行打印0..4但我得到
1072693249
1072693250
1072693251
1072693252
为什么会发生这种情况?
I am trying to print a simple int output using a for loop and
incrementing a number along the way such as
unsigned int count = 0;
for( int i = 0; i < 5; i++ ){
cout << count << endl;
}
I expect just 0..4 to be printed on the following line but I get
1072693249
1072693250
1072693251
1072693252
why would this be happening?
推荐答案
我在以下环境中编译:
编译器:mingw
OS:Win 2000 professional
显示0次5次。
你能告诉我们更多关于
你的环境的信息吗?编译?
I compiled in the folloiwng environment:
Compiler: mingw
OS: Win 2000 professional
It displayed 0 5 times.
can you tell us a little more about the kind of environment in which
you are compiling?
你确定要在for循环中打印''count''吗?你似乎是期待''我'
期待''我'。
我使用了follg代码并打印了0 .... 4。
#include< iostream>
main()
{
unsigned int count = 0;
for(int i = 0; i< 5; i ++){
std :: cout<< i<< std :: endl;
}
}
Are you sure you want to print ''count'' in the for loop ? You seem to be
expecting ''i''.
I used follg code and it printed 0....4.
#include <iostream>
main ()
{
unsigned int count = 0;
for( int i = 0; i < 5; i++ ){
std::cout << i << std::endl;
}
}
史蒂夫写道:
Steve wrote:
我试图使用for循环打印一个简单的int输出,并且
递增一个数字,例如
unsigned int count = 0;
for(int i = 0; i< 5; i ++){
cout<<计数<< endl;
}
我希望在下面的行上打印0..4但是我得到了
1072693249
1072693250
1072693251 > 1072693252
为什么会发生这种情况?
I am trying to print a simple int output using a for loop and
incrementing a number along the way such as
unsigned int count = 0;
for( int i = 0; i < 5; i++ ){
cout << count << endl;
}
I expect just 0..4 to be printed on the following line but I get
1072693249
1072693250
1072693251
1072693252
why would this be happening?
你显示5次显示0。再次尝试使用粘贴的代码
,并告诉我们您输出的内容。
如果要显示0到4,请使用 ; I"在cout。
You shuld be getting 0 displayed 5 times. Try again with the code you
have pasted and let us know what you get as output.
If you want 0 to 4 to be displayed then use "i" in cout.
这篇关于int表示不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!