vj wrote:

> #include <iostream.h>

> #include <fstream.h>

> #include <stdio.h>

> #include <math.h>

> #include <stdlib.h>

> #include <stddef.h>

> #include <complex.h>

> #include <iostream.h>

> #include <fstream.h>

> #include <iostream.h>

> #include <fstream.h>

> #include <stdio.h>

> #include <math.h>

> #include <stdlib.h>

> #include <stddef.h>
You are including

- iostream.h three times

- fstream.h three times

- stdio.h two times

- math.h two times

- stdlib.h two times

- stddef.h two times

Of those, the first two are not even part of standard C++ and the others

are deprecated. Several modern compilers don't even provide these

pre-standard IOStreams. This means two things:

1. It's hard to diagnose what's wrong without even knowing what is going on

and we don't know that because it is not standardised.

2. You need to update your knowledge about C++. Go to accu.org and pick a

good book from the reviews section.

> #define PI 3.14159265

> #define c 2.997924591e8
double const pi = 3.14159265;

double const c = 2.997924591e8;

Using #define might accidentally change other code that uses these to e.g.

define function parameters or local variables. On a cursory glance, this

doesn't even use 'c' then...

> #define double_complex complex<double>
Dito, but here you rather use a typedef.

>

> main()
No even halfway modern C++ compilers accepts main() without a returnvalue

(which is int, btw).

> ofstream outfile("MyProg.dat", ios:ut);

> double_complex j(0,1);

>

> double lambda_0 = 1.5e-6;

> double L = 100000.0e-3;

> double n = 1.5;

> double dn=0.001;

> double prd=lambda_0/2.0/n;

> double cc=PI*dn/(2.0*n*prd);

>

> double_complex r;

>

> for (double x=lambda_0-1.4e-6; x<=lambda_0; x=x+(2.0*1.4e-6/500.0)){

> double detuning = (2.0*PI*n/x)-(PI/prd);

>

> r =-cc/(sqrt(cc*cc-detuning*detuning)

> *(1.0/tanh(sqrt(cc*cc-detuning*detuning)*L))-j*detuning);
I guess somewhere in this code it fails, not in any stream operations,

right? If so, please remove all that is not necessary (in particular the

redundant headers and the stream operations) and then post a *_minimal_*

example. Also, please tell us where exactly your program fails.

> outfile.close();

> }
You know that streams are closed automatically when the stream object goes

out of scope?

Uli

--

FAQ:

http://ma.rtij.nl/acllc-c++.FAQ.html