本文介绍了奇怪的FOR LOOP问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我有这个代码时,a和b'的值永远不会增加。


for(int i = 0,double a = 0.0,double b = 0.0; i< 100; a + = 0.1,b + = 0.2)

{

printf("%s \ n",i + a + b);

}


然而这是有效的:


double a = 0.0,b = 0.0;


for(int i = 0; i< 100; a + = 0.1,b + = 0.2)

{

printf("%s \ n" ,我+ a + b);

}


我使用visual c ++ 6.0


该死的花了我四个小时才赶上这个。当然,我的原始代码

更加复杂。


有没有办法将文本打印到控制台窗口,即使你的项目

是win32应用程序?

解决方案




是的。然而,它在C ++语言新闻组中完全偏离主题。你想在microsoft.public.vc.language中询问

。 FWIW:


< OT>

查找CreateConsoleScreenBuffer"在MSDN中查看相关的

控制台功能 (链接在页面底部)。

< / OT>


HTH,


Stuart 。




这是语法错误。




这不是语法错误。这是一个语义错误。 i + a + b不是字符串。

但是C ++语言语法并不关心格式字符串。



是的。




是什么?



为什么要告诉我们这个?




因为他需要帮助吗?



谁在乎?




显然你不是。那你为什么不回到你所做的任何事情?

来到这里侮辱人们?


-

Attila aka WW





请将此问题发布到Windows编程新闻组。这个是仅用于标准C ++语言的



-

Attila aka WW

When I had this code, a and b''s value never increases.

for( int i=0, double a=0.0, double b=0.0 ; i<100; a+=0.1, b+=0.2 )
{
printf( "%s\n", i+a+b );
}

This works, however:

double a=0.0, b=0.0;

for( int i=0 ; i<100; a+=0.1, b+=0.2 )
{
printf( "%s\n", i+a+b );
}

I used visual c++ 6.0

Damn it took me four hours to catch this. Of course, my original code
is whole lot more complicated.

Is there a way to print text to a console window even if your project
is "win32 application"?

解决方案



Yes. It''s entirely off-topic in a C++ language newsgroup, however. You want
to ask this in microsoft.public.vc.language. FWIW:

<OT>
Look up "CreateConsoleScreenBuffer" in MSDN and check out the related
"Console Functions" (link at the bottom of the page).
</OT>

HTH,

Stuart.




That''s a syntax error.



That is not a syntax error. It is a semantic error. i+a+b is not a string.
But the C++ language syntax does not care about the format string.



Yes.



Yes what?



Why are you telling us this?



Because he needs help?



Who cares?



Apparently you don''t. So why don''t you just go back to whatever you did
before you came in here to insult people?

--
Attila aka WW




Please post this question to a Windows programming newsgroup. This one is
only for the standard C++ language.

--
Attila aka WW


这篇关于奇怪的FOR LOOP问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 16:52
查看更多