In this program fill 1D array and... there is no problem with cout in it when we want to print result to file this error happens:
terminate called after throwing an instance of 'std::bad_cast'
  what():  std::bad_cast
Here's the code:
#include <iostream>
#include<cmath>
#include<fstream>
using namespace std;
int main()
{
    ofstream ozon("real.txt");
    double E[100],H[100];
    double a,b;
    a=0.5,b=0.5; 
    int step,l=20;
    cout<<"please Enter step: ";
    cin>>step;
    for(int k=-10;k<=l;k++)
    {
        E[k]=0 , H[k]=0;
    } 
    for(int s=1;s<=step;s++)
    {   
        int roze=0;
        for(int m=0;m<=l;m++)
        {
            E[m]=20*sin(0.314*m);
            for(int n=1;n<=l;n++) 
            {
                float k;
                k= b*( (H[n-1])-(H[n])) ;
                if(abs(k)<0.00001 || abs(k)>10000) k=roze;
                E[n] = E[n] +k ;
            }
            for(int n=1;n<=l;n++) 
            {
                float s;
                s= a*((E[n])-(E[n+1]));             
                if(abs(s)<0.00001 || abs(s)>10000) s=roze;
                H[n] = H[n] + s ;               
            }
        }
    }
    float x,y;
    for(int n=0;n<=20;n++)
    {
        x = E[n] ;
        y = H[n] ;
        cout<<n<<"   "<<x<<"   "<<y<<endl;  
        ozon<<n<<"   "<<x<<"   "<<y<<endl;
    }
    return 0;
}
 
     
    