mt4如何输出到csv文件多列

 

代码如下所示,输出的都在csv文件的同一列,我需要输出到不同的列。或者输出数组到文件也可以,我输出数组到文件不成功


void WriteData(const int n) 

  { 
//--- open the file 
   ResetLastError(); 
   int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_WRITE|FILE_CSV); 
   if(file_handle!=INVALID_HANDLE) 
     { 
      //--- write array data to the end of the file 
      FileSeek(file_handle,0,SEEK_END); 
      FileWrite(file_handle,Close[0],Close[1],Close[2]); 
      //--- close the file 
      FileClose(file_handle); 
     } 
   else 
      Print("Failed to open the file, error ",GetLastError()); 
  }
 
int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_WRITE|FILE_CSV,','); 
 
mobanche:

代码如下所示,输出的都在csv文件的同一列,我需要输出到不同的列。或者输出数组到文件也可以,我输出数组到文件不成功


void WriteData(const int n) 

  { 
//--- open the file 
   ResetLastError(); 
   int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_WRITE|FILE_CSV); 
   if(file_handle!=INVALID_HANDLE) 
     { 
      //--- write array data to the end of the file 
      FileSeek(file_handle,0,SEEK_END); 
      FileWrite(file_handle,Close[0],Close[1],Close[2]); 
      //--- close the file 
      FileClose(file_handle); 
     } 
   else 
      Print("Failed to open the file, error ",GetLastError()); 
  }

个人经验,用   int filehandle=FileOpen(filename,FILE_READ | FILE_WRITE |FILE_TXT)打开文件,

用 string str=StringFormat("%g,%g, %g",Close[0],Close[1],Close[2]) 生成带","号分隔的内容,

用FileWriteString(filehandle,str+"\r\n") 写入,则不会出现混乱的情况。



原因: