如何让解决devcpp编译提示main' must return 'int'?

本文解决DevCPP中使用void main编译错误的问题,提供正确的代码存储方式和英文文件名建议,确保程序正常运行。

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

为什么devcpp编译提示main’ must return ‘int’?

相信很多c语言的初学者都会遇到这个问题,百度得知,dev执行的c语言标准已经不准有void main 这种形式出现,说是只有int main 或者是main() 才可以正常编译,但事实上dev仍然可以可以以void main形式出现,根据我的实际操作,得出来以下原因:

  1. 编写代码时如果要用void main,就不要在项目里面新建,否则不管怎么修改文件属性都会错误提示
#include <stdio.h>
void main(){
	printf("%f\n",1/3);
}
```![如果我在项目里新建一个代码文件,就会提示'main must return int',改变它的存储方式还是不行,因为它始终在该项目文件](https://img-blog.csdnimg.cn/20181231171354978.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzY0OTk1OA==,size_16,color_FFFFFF,t_70)
 2. 排除上述原因,如果还报错的话,就是你代码文件名或者代码存储方式错误,如下图![文件名一定要是英文!!,要养成用英文得习惯!!!!!!](https://img-blog.csdnimg.cn/20181231172206374.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzY0OTk1OA==,size_16,color_FFFFFF,t_70)
 3. 修改后的代码运行成功![如果在这一步还出问题的话就改一下存储方式,不过应该不会了!](https://img-blog.csdnimg.cn/20181231172522765.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzY0OTk1OA==,size_16,color_FFFFFF,t_70)
 4. 最后,这是我2018年最后一天写的第一篇技术性文章,虽然技术水平不咋地,但希望能帮助更多和我一样坚持不懈的有志青年,希望能在博客上认识更多的同行者,以梦为马,不负韶华!

#include <iostream> #include <vector> #include <thread> #include <chrono> using namespace std; const int rows = 10; const int cols = 10; // 计算周围存活细胞数量 int countNeighbors(const vector<vector<bool>>& grid, int x, int y) { int count = 0; for (int i = -1; i <= 1; ++i) { for (int j = -1; j <= 1; ++j) { if (i == 0 && j == 0) continue; // 跳过自身 int nx = (x + i + rows) % rows; // 循环边界处理 int ny = (y + j + cols) % cols; if (grid[nx][ny]) ++count; } } return count; } // 更新网格状态 void updateGrid(vector<vector<bool>>& grid) { vector<vector<bool>> newGrid = grid; for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { int neighbors = countNeighbors(grid, i, j); if (grid[i][j]) { newGrid[i][j] = (neighbors == 2 || neighbors == 3); } else { newGrid[i][j] = (neighbors == 3); } } } grid = newGrid; } // 打印网格 void printGrid(const vector<vector<bool>>& grid) { system("cls"); // 清屏(Windows系统) for (const auto& row : grid) { for (bool cell : row) { cout << (cell ? '■' : ' ') << ' '; } cout << endl; } } int main() { vector<vector<bool>> grid(rows, vector<bool>(cols, false)); // 初始化滑翔机模式 grid[1][2] = true; grid[2][3] = true; grid[3][1] = true; grid[3][2] = true; grid[3][3] = true; while (true) { printGrid(grid); updateGrid(grid); this_thread::sleep_for(chrono::milliseconds(500)); // 延迟500ms } return 0; }修改错误32 2 C:\Program Files (x86)\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.46 29 C:\Users\Administrator\Desktop\未命名1.cpp [Warning] m
03-15
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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值