gpt4 book ai didi

c++ - For循环中的多个计数器问题

转载 作者:IT老高 更新时间:2023-10-28 21:43:34 26 4
gpt4 key购买 nike

为什么这是无效的

for( int i = 0, int x = 0; some condition; ++i, ++x )

这是

int i, x;
for( i = 0, x = 0; some condition; ++i, ++x )

谢谢

最佳答案

when you need to declare two variables of different types, it can't be done by one declaration

Hackety hack:

for (struct {int i; char c;} loop = {0, 'a'}; loop.i < 26; ++loop.i, ++loop.c)
{
std::cout << loop.c << '\n';
}

;-)

关于c++ - For循环中的多个计数器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2340073/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com