문제

Is there any way to use an anonymous array in a ranged for loop? I'm trying to do something like this

for(auto i: {1,2,3,5,7,11,17}) //do something
도움이 되었습니까?

해결책

Yes there is; it looks like this:

#include <initializer_list>  //MUST INCLUDE THIS!

for(auto i: {1,2,3,5,7,11,17}) //do something

다른 팁

You may have trouble because there is no type ... instead of auto declare "i" as integer.

regards

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top