从我的之前的问题可以看出,我对编程有点陌生。我想问一下是否有人能帮助我解决最近遇到的问题。我正在尝试使用g++编译脚本main.cpp,但是我得到了以下错误:
Donny@Donny-PC /cygdrive/c/Users/Donny/Desktop/equation/equations/equations
$ g++ main.cpp -o don.exe
main.cpp:3:11: error: ‘::main’ must return ‘int’
void main(){
^
main.cpp: In function ‘int main()’:
main.cpp:36:22: error: ‘pow’ was not declared in this scope
float n=pow(10.0,9.0);
^
main.cpp:43:27: error: ‘sin’ was not declared in this scope
float R56=(lb1/sin(theta1)) * ((tan(theta1))-theta1) + (lb2/sin(theta1)) * ((tan(theta1))-theta1) +
^
main.cpp:43:44: error: ‘tan’ was not declared in this scope
float R56=(lb1/sin(theta1)) * ((tan(theta1))-theta1) + (lb2/sin(theta1)) * ((tan(theta1))-theta1) +
^
main.cpp:48:40: error: ‘cos’ was not declared in this scope
d*((pow(tan(theta1),2))/cos(theta1)) +
^
奇怪的是,当使用Microsoft Visual Studio 2010 C++编译时,此代码可以正常工作。非常感谢您的帮助!
编辑:
因此,我已经修复了上面显示的很多错误,但我仍然有一点难以解决void main错误。以下是我的代码:
#include<iostream>
#include<cmath>
using namespace std;
void main(){
float r, i, f, beta, alpha;
cout<<"Enter value of R : ";............
任何帮助或示例将不胜感激。
main
定义更改为int
,并在成功完成后返回0
。其他错误可能是由于您省略了<cmath>
(我认为这些函数在其中定义)引起的。 - wolfPack88main()
函数不尝试返回任何内容,它就可以被微软的 C++ 编译器允许。 - Charles E. Grantgulp.watch
编写代码时,在一个单独的终端窗口中用-Wall
运行win-LLVM clang,以显示编译错误。 - Qix - MONICA WAS MISTREATED