Xcode

Mods's I'm not sure exactly where something like this would go but this was the best I could do

**********************************

I use Xcode for writing numerical code in C++ but when I try to compile the same code in Windows XP, (Bloodshed), Salford C++ compiler and Visual C++ I keep getting errors. The Salford compiler compiles the code but gives me execution errors. Visual C++ and Bloodshed gives me weird errors ( i.e. Visual C++ thought "cout << " was a undeclared function) when compiling. What I'm thinking is casuing the problem is the way I'm starting out my source code.

***************

# include

# include

# include

using namespace std;

****************

So does anyone have any others idea's and does anyone have a solution to my dilemma. Pretty much I would like to use both macs and pc's to compile the same code

#268017

I always rember doing "#include "

#268028

I always rember doing "#include "

that's the C way on doing it, not the C++ way

could you show me the exact error you get in Visual C++ ?

#268038

You shure, i never learned C :/

that's the C way on doing it, not the C++ way

could you show me the exact error you get in Visual C++ ?

#268041

I think raduking means that its a little old fashioned to include iostream that way but it still works.

@idicula: I'm not sure why you're getting errors - I did some C++ programs on Xcode then used the source on Codewarrior. What is your error message?

#268054

If I remember C++...

#include <iostream>

using namespace std;

...and

#include <iostream.h>

...give you the same results.

#268064

#include is simply wrong. Many compilers still support it tho, because there's quite some code that needs to be compiled from before the standard ('98).

#include <iostream>

using namespace std;

and

#include <iostream.h>

are not equivalent: iostream.h is not a std-header and thus nothing of the code resides in the std-namespace.

#268069

well for salford compiler I got an error saying that my function QBar() was not valid and that my array wasn't right anyway here's my code.

//Jinu Idicula
//Aersp 302
//March 21 2005
//Composites Project
//Penn State Univ. Dept. of Aerospace Eng.

# include <iostream>
# include <cmath>
# include <fstream>
using namespace std;

void QBar();

int main()
{
QBar();
return 0;
}



void QBar() //Funct. calculating Qbar and A,B,D Matrices
{
double Q11,Q22,Q12,Q66,Q16,Q26;
double QBar11[5];double QBar12[5];double QBar16[5];double QBar22[5];double QBar26[5];double QBar66[5];
double theta[5];
const double pi = 3.141592653589793238;
int num;
Q11 = 151.2;
Q22 = 20.2;
Q12 = 5.04;
Q66 = 5;
Q16 = 0;
Q26 = 0;

int input;
cout << "Please enter a number for this specific case(1-7)" << endl;
cin >> input;

ofstream outdata;

switch(input)
{
case 1: outdata.open("outdata1.txt"); break;
case 2: outdata.open("outdata2.txt"); break;
case 3: outdata.open("outdata3.txt"); break;
case 4: outdata.open("outdata4.txt"); break;
case 5: outdata.open("outdata5.txt"); break;
case 6: outdata.open("outdata6.txt"); break;
case 7: outdata.open("outdata7.txt"); break;
default: cout << endl << "Error" << endl << "Error" << endl << "Error" << endl;
}


double A11 = 0; double A22 = 0; double A12 = 0; double A66 = 0; double A16 = 0; double A26 = 0;
double B11 = 0; double B12 = 0; double B66 = 0; double B16 = 0; double B26 = 0; double B22 = 0;
double D11 = 0; double D22 = 0; double D12 = 0; double D66 = 0; double D16 = 0; double D26 = 0;
double zk[5]; double zkplus1[5];
const double tk = .134;

zk[0] = -3*tk; zk[1] = -2*tk; zk[2] = -tk; zk[3] = 0; zk[4] = tk; zk[5] = 2*tk;
zkplus1[0] = -2*tk; zkplus1[1] = -tk; zkplus1[2] = 0; zkplus1[3] = tk; zkplus1[4] = 2*tk; zkplus1[5] = 3*tk;


for (num = 0; num <= 5; num ++)
{
cout << "Please enter a value for theta" << "["<< num << "]" << endl;
cin >> theta[num];
theta[num] = (theta[num]*pi)/180;




QBar11[num] = Q11*pow(cos(theta[num]),4) + Q22*pow(sin(theta[num]),4) + 2*(Q12 + 2*Q66)*pow(sin(theta[num]),2)*pow(cos(theta[num]),2);
QBar22[num] = Q11*pow(sin(theta[num]),4) + Q22*pow(cos(theta[num]),4) + 2*(Q12 + 2*Q66)*pow(sin(theta[num]),2)*pow(cos(theta[num]),2);
QBar12[num] = ((Q11 + Q22 - (4*Q66))*(pow(sin(theta[num]),2)*pow(cos(theta[num]),2))) + (Q12*(pow(sin(theta[num]),4) + pow(cos(theta[num]),4)));

QBar66[num] = (Q11 + Q22 - 2*Q12 - 2*Q66)*pow(sin(theta[num]),2)*pow(cos(theta[num]),2)+ Q12*(pow(sin(theta[num]),4) + pow(cos(theta[num]),4));
QBar16[num] = (Q11 - Q12 - 2*Q66)*sin(theta[num])*pow(cos(theta[num]),3) - (Q22 - Q12 - 2*Q66)*pow(sin(theta[num]),3)*cos(theta[num]);
QBar26[num] = (Q11 - Q12 - 2*Q66)*pow(sin(theta[num]),3)*cos(theta[num]) - (Q22 - Q12 - 2*Q66)*sin(theta[num])*pow(cos(theta[num]),3);

A11 = A11 + QBar11[num]*(zkplus1[num]-zk[num]);
A22 = A22 + QBar22[num]*(zkplus1[num]-zk[num]);
A12 = A12 + QBar12[num]*(zkplus1[num]-zk[num]);
A66 = A66 + QBar66[num]*(zkplus1[num]-zk[num]);
A16 = A16 + QBar16[num]*(zkplus1[num]-zk[num]);
A26 = A26 + QBar26[num]*(zkplus1[num]-zk[num]);

B11 = B11 + QBar11[num]*((pow(zkplus1[num],2)-pow(zk[num],2))*.5);
B12 = B12 + QBar12[num]*((pow(zkplus1[num],2)-pow(zk[num],2))*.5);
B66 = B66 + QBar66[num]*((pow(zkplus1[num],2)-pow(zk[num],2))*.5);
B16 = B16 + QBar16[num]*((pow(zkplus1[num],2)-pow(zk[num],2))*.5);
B26 = B26 + QBar26[num]*((pow(zkplus1[num],2)-pow(zk[num],2))*.5);
B22 = B22 + QBar22[num]*((pow(zkplus1[num],2)-pow(zk[num],2))*.5);

D11 = D11 + QBar11[num]*((pow(zkplus1[num],3)-pow(zk[num],3))*.333);
D22 = D22 + QBar22[num]*((pow(zkplus1[num],3)-pow(zk[num],3))*.333);
D12 = D12 + QBar12[num]*((pow(zkplus1[num],3)-pow(zk[num],3))*.333);
D66 = D66 + QBar66[num]*((pow(zkplus1[num],3)-pow(zk[num],3))*.333);
D16 = D16 + QBar16[num]*((pow(zkplus1[num],3)-pow(zk[num],3))*.333);
D26 = D26 + QBar26[num]*((pow(zkplus1[num],3)-pow(zk[num],3))*.333);



}

outdata << A11 <<" "<< A12 <<" "<< A16 << " "<< A22 <<" "<< A26 << " " << A66 << endl;

outdata << B11 <<" "<< B12 <<" "<< B16 << " "<< B22 <<" "<< B26 << " " << B66 << endl;

outdata << D11 <<" "<< D12 <<" "<< D16 << " "<< D22 <<" "<< D26 << " " << D66 << endl;

}

#268111