gcc+mingw 编译后报错 error:'::main' must return 'int'

本文介绍了一个简单的C程序,该程序用于寻找数组中的最大值和最小值,并记录了在使用mingw编译器进行编译时遇到的错误:main函数必须返回int类型。文章解释了如何通过更改main函数的声明来解决这个问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

写了一个c程序,

#include 

void main()
{
	float a[20],min,max;
	int i;
	for(i=0;i<20;i++)
	{
		printf("Please input the %dth number.",i+1);
		scanf("%f",&a[i]);
	}
	min=a[0];
	max=a[0];
	for(i=1;i<20;i++)
	{
		if(a[i]max)
		{
			max=a[i];
		}
		printf("min=%f,max=%f",min,max);
	}
	//return 0;
}

用mingw编译后提示如下错误


 error: '::main' must return 'int'

 void main()

           ^

改正办法是:

将void main()改为int main()就行了。原因我没有深究。

35 0 F:\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\random In file included from F:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/random 4 C:\Users\余伟杰\Desktop\RSA.cpp from C:\Users\余伟杰\Desktop\RSA.cpp 32 2 F:\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\c++0x_warning.h [Error] #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options. C:\Users\余伟杰\Desktop\RSA.cpp In function 'bool isPrime(long long int, int)': 33 5 C:\Users\余伟杰\Desktop\RSA.cpp [Error] 'random_device' was not declared in this scope 34 5 C:\Users\余伟杰\Desktop\RSA.cpp [Error] 'mt19937' was not declared in this scope 35 5 C:\Users\余伟杰\Desktop\RSA.cpp [Error] 'uniform_int_distribution' was not declared in this scope 35 30 C:\Users\余伟杰\Desktop\RSA.cpp [Error] expected primary-expression before 'long' 38 27 C:\Users\余伟杰\Desktop\RSA.cpp [Error] 'gen' was not declared in this scope 38 30 C:\Users\余伟杰\Desktop\RSA.cpp [Error] 'dis' was not declared in this scope C:\Users\余伟杰\Desktop\RSA.cpp In function 'long long int generateLargePrime(int)': 59 5 C:\Users\余伟杰\Desktop\RSA.cpp [Error] 'random_device' was not declared in this scope 60 5 C:\Users\余伟杰\Desktop\RSA.cpp [Error] 'mt19937' was not declared in this scope 61 5 C:\Users\余伟杰\Desktop\RSA.cpp [Error] 'uniform_int_distribution' was not declared in this scope 61 30 C:\Users\余伟杰\Desktop\RSA.cpp [Error] expected primary-expression before 'long' 65 21 C:\Users\余伟杰\Desktop\RSA.cpp [Error] 'gen' was not declared in this scope 65 24 C:\Users\余伟杰\Desktop\RSA.cpp [Error] 'dis' was not declared in this scope C:\Users\余伟杰\Desktop\RSA.cpp In function 'void generateRSAKeys(RSAKey&, RSAKey&, int)': 103 22 C:\Users\余伟杰\Desktop\RSA.cpp [Error] 'gcd' was not declared in this scope 108 22 C:\Users\余伟杰\Desktop\RSA.cpp [Warning] extended initializer lists only available with -std=c++11 or -std=gnu++11 108 15 C:\Users\余伟杰\Desktop\RSA.cpp [Warning] extended initializer lists only available with -std=c++11 or -std=gnu++11 109 23 C:\Users\余伟杰\Desktop\RSA.cpp [Warning] extended initializer lists only available with -std=c++11 or -std=gnu++11 109 16 C:\Users\余伟杰\Desktop\RSA.cpp [Warning] extended initializer lists only available with -std=c++11 or -std=gnu++11 C:\Users\余伟杰\Desktop\RSA.cpp In function 'std::vector<long long int> rsaEncrypt(const string&, const RSAKey&)': 115 19 C:\Users\余伟杰\Desktop\RSA.cpp [Error] range-based 'for' loops are not allowed in C++98 mode 117 19 C:\Users\余伟杰\Desktop\RSA.cpp [Error] redeclaration of 'long long int c' 115 15 C:\Users\余伟杰\Desktop\RSA.cpp [Note] 'char c' previously declared here C:\Users\余伟杰\Desktop\RSA.cpp In function 'std::string rsaDecrypt(const std::vector<long long int>&, const RSAKey&)': 126 24 C:\Users\余伟杰\Desktop\RSA.cpp [Error] range-based 'for' loops are not allowed in C++98 mode C:\Users\余伟杰\Desktop\RSA.cpp In function 'int main()': 147 24 C:\Users\余伟杰\Desktop\RSA.cpp [Error] range-based 'for' loops are not allowed in C++98 mode
最新发布
07-07
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值