24小时热门版块排行榜    

查看: 2203  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 投票:  有多少人是今天查系统知道结果的? +16 爱看书的可乐 2026-08-26 18/900 2026-08-29 00:28 by winsaint
[基金申请] 国自然评审意见 +11 wangmingqi 2026-08-28 15/750 2026-08-29 00:17 by fangyl2005
[基金申请] 为什么资助数各大高校都创新高,自己申请怎么就这么难 +12 Kittylucky 2026-08-27 13/650 2026-08-29 00:04 by superceng
[基金申请] 基金不中,共勉 +11 eulota 2026-08-26 11/550 2026-08-28 14:22 by 火星超人xi
[基金申请] 2026年叶企孙基金 +3 bud_bud 2026-08-27 6/300 2026-08-28 11:53 by bud_bud
[基金申请] 怎么查啊 +6 huang1991js 2026-08-26 6/300 2026-08-28 08:42 by winsaint
[基金申请] 面上合作单位盖章 +5 ssyjh 2026-08-27 5/250 2026-08-27 20:50 by gdfollow
[基金申请] 申请删除本帖 +6 lyz123lyz 2026-08-27 7/350 2026-08-27 17:31 by 宁静致远sy
[基金申请] 基金未中,这种答复是模板吗? +5 zhaosm1982 2026-08-27 6/300 2026-08-27 16:00 by lfy8008
[基金申请] 看板上这么多中的,有点像50人群里49个人都是骗子的那种感觉…… +5 a089 2026-08-26 6/300 2026-08-27 14:05 by jonewore
[基金申请] 怎么看青基中了没有啊 +5 叶九微 2026-08-26 5/250 2026-08-27 10:35 by l_zh2008
[基金申请] 为什么 国际(地区)合作与交流项目 没有放榜? 10+3 majunge000 2026-08-26 11/550 2026-08-27 08:42 by 北京莱茵编辑
[基金申请] 2026年的国家社科基金项目通讯评审的新规则与新动向、新挑战 +7 process2012 2026-08-23 10/500 2026-08-26 19:23 by hmhminy
[基金申请] 2026年8月25日国自然放榜前突然收到列入评审专家邮件,有关系吗? +25 木水思豆 2026-08-25 28/1400 2026-08-26 14:53 by draco1987
[基金申请] 为什么国自然不能直接公布 +4 bjdxyxy 2026-08-26 4/200 2026-08-26 13:12 by qingmu1201
[基金申请] 国合里面能看到了 +7 一怀馨秋 2026-08-26 7/350 2026-08-26 11:23 by zhaosm1982
[基金申请] 国际合作可查了,中了面上 (EPI+1)(金币+50) +18 Ldrop2023 2026-08-26 18/900 2026-08-26 11:15 by cmrandy
[基金申请] 项目信息和经费信息在系统里都可以看到了 +6 wittyboy 2026-08-26 14/700 2026-08-26 10:55 by wittyboy
[基金申请] 今天务委会开完了,明天出结果吗 +19 angus9576 2026-08-25 23/1150 2026-08-26 10:03 by zp519
[基金申请] 在坚冰还盖着北海的时候,我看到了怒放的梅花。 (金币+10) +6 ziyangfang 2026-08-25 9/450 2026-08-25 20:26 by huagongfeihu
信息提示
请填处理意见