输出文件中的编码问题 - C ++

时间:2017-08-14 04:50:56

标签: c++ encoding io

program.cpp源代码的序言:

#include <omp.h>
#include <iostream>
#include <fstream>
#include <gsl/gsl_sf_gamma.h>
#include <gsl/gsl_integration.h>
#include "program.h"

program.h中,值得一提的是

的存在
HyperInterpStruct* pHIS;        

int l_index;        

static const int ni;        

int nk;

构建我的covariance类,我首先定义

const int covariance::ni=2048;

然后插入一个函数

void covariance::calculate_signal (HyperInterpStruct* pBIS, int L)
{
  pHIS=pBIS;
  l_index=L;


gsl_matrix* Gl=gsl_matrix_calloc(nk,ni);
calculate_G(Gl);
std::ofstream out;

  if(l_index==1)
  {
  out.open("out.txt", std::ios::out);
  }
  else
  {
  out.open("out2.txt", std::ios::out);    
  }

# pragma omp parallel for
  for (int i=0; i<nk; ++i)
  {
    for (int j=0; j<nk; ++j)
    {
      double Aij=gsl_matrix_get(Gl,i,j);
      out << i << "\t" <<  j <<  "\t" << Aij << std::endl;

    }
  }
out.close();
gsl_matrix_free(Gl);
} 

计算G矩阵的函数定义如下:

void covariance::calculate_G (gsl_matrix* Gl)
{
 //the definition of G is too long and unnecessary to the purpose of this question. Perhaps the only thing worth mentioning is that it depends on another function, F, defined below
}

double covariance::F (double z, double k)
{
//again, the definition of F is too long and unnecessary. Perhaps the only thing worth mentioning is that it depends on another class which takes as input `pHIS` and `l_index`  
  Anotherclass anotherclass(k,pHIS,l_index);
}

我面临的问题是我的输出文件&#34; out.txt&#34;和&#34; out1.txt&#34;充满了奇怪的符号,显然存在编码问题,我不知道为什么。

我包含main.cpp文件:

#include <iostream>
#include <fstream>
#include "hyperspherical.h"
#include <gsl/gsl_matrix.h>
using namespace std;

int main ()
{


  int nk=500;                   
  double kmin=5.e-3;            
  double kmax=1.;               

  int *l_steps;
  int number_of_l_steps = 2;
  int l_max = 500;
  int l_min = 100;
  l_steps=new int[number_of_l_steps];

  for (int i=0; i<number_of_l_steps; ++i)
  {
    l_steps[i]=l_min+i*(l_max-l_min)/(number_of_l_steps-1);
  }
  int l_bessel[2*number_of_l_steps];
  for (int i=0; i<number_of_l_steps; ++i)
  {
    l_bessel[2*i]=l_steps[i]-1;
    l_bessel[2*i+1]=l_steps[i];
  }
  double x_bessel_min = 1.e-5;
  double x_bessel_max = 1.e5;
  double sampling = 150.;
  double j_l_min=1.e-13;
  ErrorMsg bessel_error_message;
  hyperspherical_HIS_create(0,1.,2*number_of_l_steps,l_bessel,x_bessel_min,x_bessel_max,sampling,l_steps[number_of_l_steps-1]+1,j_l_min,&HIS,bessel_error_message);
  survey sv(&sd,sigma_epsilon,&ph,f_sky,l_max,cp);
  covariance cv(nk,kmin,kmax,&sv,cp,false,true);

  double zmin = 0.1;
  double zmax = 4.;
  double kmin1= 1.e-2;
  int ni = 2048;

  for(int elle = 0; elle<number_of_l_steps; elle++)
  {
         cv.calculate_signal(&HIS,2*elle+1);
  }

  return 0;
}

0 个答案:

没有答案