[C ++问题]用于循环多次初始化 [英] [C++ Question] For loop Multiple Initialization
问题描述
嗨C ++用户,
for(int i = 0,int j = 10; i< 5&& j< 10; i ++,j--){}
示例来自: http:// www.tech-faq.com/iterations.shtml
在我的eclipse cdt中无效。
C ++中有多个初始化?我们怎么能用呢?
谢谢!
查理
Hi C++ users,
for(int i=0,int j=10 ; i<5&&j<10 ; i++ , j--) {}
example from: http://www.tech-faq.com/iterations.shtml
Is not valid in my eclipse cdt.
Is there multiple initialization in C++? How can we use that?
Thanks!
Charlie
推荐答案
----- BEGIN PGP签名消息-----
哈希:SHA1
ch ************* @ gmail.com 写道:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
ch*************@gmail.com wrote:
C ++用户,
for(int i = 0,int j = 10; i< 5& j< 10; i ++,j--){}
示例来自: http:/ /www.tech-faq.com/iterations.shtml
在我的eclipse cdt中无效。
C ++中有多个初始化?我们怎么用呢?
Hi C++ users,
for(int i=0,int j=10 ; i<5&&j<10 ; i++ , j--) {}
example from: http://www.tech-faq.com/iterations.shtml
Is not valid in my eclipse cdt.
Is there multiple initialization in C++? How can we use that?
这种方式是正确的:
for(int i = 0,j = 10; i< 5&& ; j< 10; i ++,j--){}
除非我错了,否则无法初始化不同的变量
类型在for循环的那一部分。
Pawel Dziepak
-----开始PGP签名-----
版本:GnuPG v1.4.9(GNU / Linux)
评论:在Fedora中使用GnuPG - http://enigmail.mozdev.org
iEYEARECAAYFAkkPb5AACgkQPFW + cUiIHNo4jQCff0Shc8Rmg8 IbW7OYSDPqVu5g
7dsAoLirnTWj3mIPx2eN9mnZPUNBsYi1
= 4L + S
----- END PGP SIGNATURE -----
That way is correct:
for (int i=0, j=10; i<5 && j<10; i++, j--) {}
Unless I''m wrong, there''s no way to initialize variables of different
types in that part of for loop.
Pawel Dziepak
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iEYEARECAAYFAkkPb5AACgkQPFW+cUiIHNo4jQCff0Shc8Rmg8 IbW7OYSDPqVu5g
7dsAoLirnTWj3mIPx2eN9mnZPUNBsYi1
=4L+S
-----END PGP SIGNATURE-----
11月3日,1: 39 * pm,Pawel Dziepak< pdzie ... @ quarnos.orgwrote:
On Nov 3, 1:39*pm, Pawel Dziepak <pdzie...@quarnos.orgwrote:
----- BEGIN PGP SIGNED MESSAGE -----
哈希:SHA1
charlie.xia .... @ gmail.com写道:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
charlie.xia....@gmail.com wrote:
C ++用户,
Hi C++ users,
for(int i = 0,int j = 10; i< 5&& j< 10; i ++,j--){}
for(int i=0,int j=10 ; i<5&&j<10 ; i++ , j--) {}
示例来自: http://www.tech-faq.com/iterations.shtml
在我的eclipse cdt中无效。
C ++中有多个初始化?我们怎么用呢?
example from:http://www.tech-faq.com/iterations.shtml
Is not valid in my eclipse cdt.
Is there multiple initialization in C++? How can we use that?
这种方式是正确的:
for(int i = 0,j = 10; i< 5&& ; j< 10; i ++,j--){}
除非我错了,否则无法初始化不同的变量
类型在for循环的那一部分。
Pawel Dziepak
That way is correct:
for (int i=0, j=10; i<5 && j<10; i++, j--) {}
Unless I''m wrong, there''s no way to initialize variables of different
types in that part of for loop.
Pawel Dziepak
它有效!
谢谢
it works!
thanks
>
----- BEGIN PGP SIGNATURE -----
版本: GnuPG v1.4.9(GNU / Linux)
评论:使用GnuPG和Fedora -http://enigmail.mozdev.org
iEYEARECAAYFAkkPb5AACgkQPFW + cUiIHNo4jQCff0Shc8Rmg8 IbW7OYSDPqVu5g
7dsAoLirnTWj3mIPx2eN9mnZPUNBsYi1
= 4L + S
----- END PGP SIGNATURE -----
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora -http://enigmail.mozdev.org
iEYEARECAAYFAkkPb5AACgkQPFW+cUiIHNo4jQCff0Shc8Rmg8 IbW7OYSDPqVu5g
7dsAoLirnTWj3mIPx2eN9mnZPUNBsYi1
=4L+S
-----END PGP SIGNATURE-----
11月3日,10:29 * pm,charlie.xia .... @ gmail.com < lxia .... @ gmail.com>
写道:
On Nov 3, 10:29*pm, "charlie.xia....@gmail.com" <lxia....@gmail.com>
wrote:
for(int i = 0,int j = 10; i< 5& j< 10; i ++,j--){}
for(int i=0,int j=10 ; i<5&&j<10 ; i++ , j--) {}
示例来自: http://www.tech-faq.com/iterations.shtml
在我的eclipse cdt中无效。
example from:http://www.tech-faq.com/iterations.shtml
Is not valid in my eclipse cdt.
它在C ++中也无效。只是另一个案例的某个人不知道该语言试图写它。
It''s not valid in C++ either. Just another case of someone who
doesn''t know the language trying to write about it.
C ++中有多个初始化?
Is there multiple initialization in C++?
排序。你只能写一个声明语句,但它可以定义多个变量,例如:
for(int i = 0,j = 10; .. 。)
一般来说,我会避免它,因为它令人困惑
在同一个声明中定义了多个变量。但是
可能有例外;我知道有些人喜欢:
for(Container :: const_iterator
current = c.begin(),end = c.end();
当前!=结束;
++当前)
我不喜欢它,但如果你加注它达到了标准成语的水平。在你的代码中,我不认为我会有任何真正的b
反对意见。
-
詹姆斯Kanze(GABI软件)电子邮件:ja ********* @ gmail.com
Conseils eninformatiqueorientéeobjet/
Beratung in objektorientierter Datenverarbeitung
9个地方Sémard,78210 St.-Cyr-l''coco,法国,+ 33(0)1 30 23 00 34
Sort of. You can only write one declaration statement, but it
can define multiple variables, e.g.:
for ( int i = 0, j = 10 ; ... )
Generally speaking, i''ld avoid it, because it is confusing to
have multiple variables defined in the same declaration. But
there are probably exceptions; I know that some people like:
for ( Container::const_iterator
current = c.begin(), end = c.end() ;
current != end ;
++ current )
I''m not that fond of it, but if you raise it to the level of a
"standard idiom" in your code, I don''t think I''d have any real
objections.
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l''école, France, +33 (0)1 30 23 00 34
这篇关于[C ++问题]用于循环多次初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!