简单的C ++程序在Xcode,代码块和终端中运行错误

时间:2012-06-18 23:51:17

标签: c++ math

我正在尝试用Euler方法编写一个简单的程序来计算数值近似值,而我使用的每个编译器都没有打印任何东西。代码块运行错误,但我认为这是因为编译器设置不正确。 xCode将构建它但没有任何反应。当我运行g ++ Euler.cpp时,我得到:

Euler.cpp:1: error: expected constructor, destructor, or type conversion before ‘<’ token
Euler.cpp: In function ‘int main()’:
Euler.cpp:13: error: ‘cin’ was not declared in this scope
Euler.cpp:19: error: ‘cout’ was not declared in this scope
Euler.cpp:19: error: ‘endl’ was not declared in this scope

我通常不会遇到简单的c ++程序问题,并担心它是非常明显的。

//
//  Euler.cpp
//  Numerical Approximations (Euler's Method)
//
//  Created by XXXXXXXXXXXX on 6/18/12.
//  Copyright (c) 2012 University of Kansas Department of Mathematics. All rights     reserved.
//

#include <iostream>
using namespace std;

int main ()
{

    int N=4;
    //cout<<"Number of steps (N):";
    //cin>>t;

    float h=0.1;
    //cout<<endl<<" Step size (h):";
    cin>>h;

    float y0=1;
    //cout<<endl<<"y(0)=";
    //cin>>y0;

    cout<<"test!"<<endl;

    float data[N][4];

    int n=0;

    data[0][2] = y0;

    while (n<N){
        data[n][0]=n;
        if(n>0){
             data[n][2]=data[n-1][3];
        }
        data[n][1]=h*n;
        data[n][3] = data[n][2] + ((3 + data[n][1] - data[n][2])*h);
        n++;
        cout<<"n="<<n<<". tn="<<data[n][1]<<". y(n)="<<data[n][2]<<". y(n+1)="<<data[n][3] <<"."<<endl;
    }




 return 0;
 }

这可能是显而易见的,但我没有看到它。

1 个答案:

答案 0 :(得分:2)

找不到iostream标头。你看到一条错误信息,上面写着“找不到标题iostream”的内容吗?