gpt4 book ai didi

c++ - 错误 : expected unqualified-id before ‘for’

转载 作者:IT老高 更新时间:2023-10-28 22:23:50 32 4
gpt4 key购买 nike

以下代码返回:error: expected unqualified-id before ‘for’

我找不到导致错误的原因。感谢您的帮助!

#include<iostream>

using namespace std;

const int num_months = 12;

struct month {
string name;
int n_days;
};

month *months = new month [num_months];

string m[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
int n[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

for (int i=0; i<num_months; i++) {
// will initialize the months
}

int main() {
// will print name[i]: days[i]
return 0;
}

最佳答案

你的 for 循环在函数体之外。

关于c++ - 错误 : expected unqualified-id before ‘for’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2293970/

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