24小时热门版块排行榜    

CyRhmU.jpeg
南方科技大学公共卫生及应急管理学院2025级博士研究生招生报考通知
查看: 1757  |  回复: 5

zyj8119

木虫 (著名写手)


[交流] 【求助】mac的编译环境xcode的使用问题

此程序,用visual studio编译完全没有问题,但是用mac下的xcode编译,却有11个错误???
CODE:
#include
#include
#include
#include

using namespace std;
class ffts
{
private:
        double a,b,eps,integ;
public:
        ffts(double aa,double bb,double es)
        {a=aa;b=bb;eps=es;}
        void integration();
        void output();
        double func (double);
};

void ffts::integration()
{
        int n,k;
        double fa,fb,h,t1,p,s,x,t;
        fa=func(a);fb=func(b);
        n=1;h=b-a;
        t1=h*(fa+fb)/2.0;
        p=eps+1.0;
        while(p>=eps)
        {
                s=0.0;
                for(k=0;k                 {
                        x=a+(k+0.5)*h;
                        s=s+func(x);
                }
                t=(t1+h*s)/2.0;
                p=fabs(t1-t);
                t1=t;n=n+n;h=h/2.0;
        }
        integ=t;
}

void ffts::output()
{
        char str2[20];
        cout<<"\n输出文件名:";
        cin>>str2;
        ofstream fout(str2);
        if(!fout)
        {cout<<"\n不能打开这个文件"<         fout<         fout.close();
}

double ffts::func(double x)
{ return exp(-x*x);}
       
void main()
{
        ffts solution(0.0,1.0,0.000001);
        solution.integration();
        solution.output();
}

Build 1 of project 1 with configuration Debug

CompileC build/1.build/Debug/1.build/Objects-normal/x86_64/main.o main.c normal x86_64 c com.apple.compilers.gcc.4_2
cd /Users/apple/Documents/1
setenv LANG en_US.US-ASCII
/Developer/usr/bin/gcc-4.2 -x c -arch x86_64 -fmessage-length=0 -pipe -std=gnu99 -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wreturn-type -Wunused-variable -isysroot /Developer/SDKs/MacOSX10.6.sdk -mfix-and-continue -mmacosx-version-min=10.6 -gdwarf-2 -iquote /Users/apple/Documents/1/build/1.build/Debug/1.build/1-generated-files.hmap -I/Users/apple/Documents/1/build/1.build/Debug/1.build/1-own-target-headers.hmap -I/Users/apple/Documents/1/build/1.build/Debug/1.build/1-all-target-headers.hmap -iquote /Users/apple/Documents/1/build/1.build/Debug/1.build/1-project-headers.hmap -F/Users/apple/Documents/1/build/Debug -I/Users/apple/Documents/1/build/Debug/include -I/Users/apple/Documents/1/build/1.build/Debug/1.build/DerivedSources/x86_64 -I/Users/apple/Documents/1/build/1.build/Debug/1.build/DerivedSources -c /Users/apple/Documents/1/main.c -o /Users/apple/Documents/1/build/1.build/Debug/1.build/Objects-normal/x86_64/main.o

/Users/apple/Documents/1/main.c:2:21: error: iostream.h: No such file or directory
/Users/apple/Documents/1/main.c:3:20: error: fstream.h: No such file or directory
/Users/apple/Documents/1/main.c:4:18: error: cmath.h: No such file or directory
/Users/apple/Documents/1/main.c:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'
/Users/apple/Documents/1/main.c:7: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'ffts'
/Users/apple/Documents/1/main.c:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
/Users/apple/Documents/1/main.c:42: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
/Users/apple/Documents/1/main.c:45: error: stray '\357' in program
/Users/apple/Documents/1/main.c:45: error: stray '\274' in program
/Users/apple/Documents/1/main.c:45: error: stray '\233' in program
/Users/apple/Documents/1/main.c:54: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token

[ Last edited by zyj8119 on 2011-4-5 at 20:28 ]
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

» 抢金币啦!回帖就可以得到:

查看全部散金贴

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zyj8119(金币+1):谢谢参与
zyj8119(金币+10): 就是想试一下XCODE. 2011-04-05 19:57:55
您还是先学习一下namespace这个玩意儿吧
2楼2011-04-05 15:54:33
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

sudo

木虫 (正式写手)



zyj8119(金币+1):谢谢参与
zyj8119(金币+10): 的确,我用VC6.0运行问题就不大。。。 2011-04-05 19:58:28
一眼看过去就发现有中文字符错误和缺大括号错误,请楼主先认真检查再贴过来...

另:
1. void main()不合标准,lz受VC6或以前版本毒害了

2. 关于头文件:
#include
#include
#include
#include
才是新式的写法

3. 虽然gcc是能编译c++程序,不过需要改一些参数。没用过xcode,我想如果正确建立C++ project的话,IDE应该是能自动选用g++编译器的。嗯,如果不能,手动把编译器从gcc改为g++。这应该是最方便的做法
3楼2011-04-05 16:26:47
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zyj8119

木虫 (著名写手)


引用回帖:
Originally posted by sudo at 2011-04-05 16:26:47:
一眼看过去就发现有中文字符错误和缺大括号错误,请楼主先认真检查再贴过来...

另:
1. void main()不合标准,lz受VC6或以前版本毒害了

2. 关于头文件:
#include <cstdio>
#include <iostream ...

CODE:
#include
#include
#include

using namespace std;
class ffts
{
private:
        double a,b,eps,integ;
public:
        ffts(double aa,double bb,double es)
        {a=aa;b=bb;eps=es;}
        void integration();
        void output();
        double func (double);
};

void ffts::integration()
{
        int n,k;
        double fa,fb,h,t1,p,s,x,t;
        fa=func(a);fb=func(b);
        n=1;h=b-a;
        t1=h*(fa+fb)/2.0;
        p=eps+1.0;
        while(p>=eps)
        {
                s=0.0;
                for(k=0;k                 {
                        x=a+(k+0.5)*h;
                        s=s+func(x);
                }
                t=(t1+h*s)/2.0;
                p=fabs(t1-t);
                t1=t;n=n+n;h=h/2.0;
        }
        integ=t;
}

void ffts::output()
{
        char str2[20];
        cout<<"\n输出文件名:";
        cin>>str2;
        ofstream fout(str2);
        if(!fout)
        {cout<<"\n不能打开这个文件"<         fout<         fout.close();
}

double ffts::func(double x)
{ return exp(-x*x);}
        
void main()
{
        ffts solution(0.0,1.0,0.000001);
        solution.integration();
        solution.output();
}

[ Last edited by zyj8119 on 2011-4-5 at 20:30 ]
4楼2011-04-05 20:29:11
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

sudo

木虫 (正式写手)


zyj8119(金币+8): 谢谢提醒!!!! 2011-04-05 22:58:54
引用回帖:
Originally posted by zyj8119 at 2011-04-05 20:29:11:
[code]#include<iostream>
#include<fstream>
#include<cmath>

using namespace std;
class ffts
{
private:
        double a,b,eps,integ;
public:
        ffts(double aa ...

前面再加上
#include
因为里面调用了exit(1);

然后再把void main()改成int main()

在我这里用g++编译就没有问题了

虽然没使用过xcode,不过它的c/c++编译器也是gcc和g++(虽然据说是苹果公司改过的),应该是差不多的


楼主看看下面这些IDE常见的步骤有没有参考价值:

打开IDE,选择新建工程(new project),然后选里面的c++工程(这样IDE会自动给你配好编译器选项),这样应该会出现一个命名类似main.cpp样子的文件,然后再把代码贴进去试试看

当然了,如果楼主对xcode的配置比较了解的话,直接将编译器配成g++就行了,那些报错的主要原因是:把C++程序当成C程序来编译了...
5楼2011-04-05 22:11:39
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zyj8119

木虫 (著名写手)


引用回帖:
Originally posted by sudo at 2011-04-05 22:11:39:
前面再加上
#include<cstdlib>
因为里面调用了exit(1);

然后再把void main()改成int main()

在我这里用g++编译就没有问题了

虽然没使用过xcode,不过它的c/c++编译器也是gcc和g++(虽然据说是 ...

谢谢建议。。。。。
6楼2011-04-24 16:18:04
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 zyj8119 的主题更新
普通表情 高级回复(可上传附件)
信息提示
请填处理意见