将数组复制到文本文件c ++错误munmap_chunk()

时间:2016-02-07 20:46:10

标签: c++ arrays text copy

您好我正在尝试创建一个存储数组值的文本文件。该程序运行良好,但当我尝试插入一些代码复制到文本文件时,我得到错误

  

munmap_chunk():无效指针munmap_chunk():无效指针

创建的文本文件为空

#include <iostream>
#include <string>
#include <cstdlib>
#include <fstream>

using namespace std;

int generator(void){
int state;
state = 1 + rand() % 2;
return state;

}


int main() {

int nwalks,nsteps,x,state; 
double XSUM1,XSUM2,xaccum; 

int *ArXACCUM = new int[nwalks]; 
int *ArXSQUARED = new int[nwalks];

cout << "Give the number of Walks :  "; 
cin >> nwalks;
cout << "Give the number of Steps :  ";
cin >> nsteps;
ofstream arrayData("/home/PATH/xaverage.txt",ios::app);  

srand(1256); 
xaccum = 0.0; 
XSUM1 = 0.0;
XSUM2 = 0.0;

for (int walks = 1; walks <= nwalks; walks++) 
{
x = 0; 

for (int steps = 1; steps <= nsteps; steps++) 
{
state = generator() ;
    if (state == 1)
        x += +1;
    else 
        x += -1;

}
     xaccum =+ x;
     ArXACCUM[walks] = xaccum;
     ArXSQUARED[walks] = xaccum*xaccum;
     XSUM1 += ArXACCUM[walks];
     XSUM2 += ArXSQUARED[walks];



}
            for (int i = 1; i <= nwalks; i++){
          arrayData << ArXACCUM[i] << endl;
         } 

  cout << " The average displacement <x> is : " << XSUM1/nwalks << endl;
  cout << " The average of the squared displacement <x^2> is : " <<      XSUM2/nwalks << endl;   
  return 0;
}

0 个答案:

没有答案