Download MetaTrader 5

How to use CFileTxt

To add comments, please log in or register
wpg
20
wpg  

The following code always returns -1.

#include <Files\FileTxt.mqh>


CFileTxt oF ;
string sFileName = "c:\tmp\FXReport.txt" ;
void OnStart()
  {
//---
    if ( oF.IsExist ( sFileName ) )
    {
      Print ( "File Exits" ) ;

      oF.Open ( sFileName, FILE_REWRITE ) ;
    }
    else
    {
      Print ( "RetCode: ", oF.Open ( sFileName, FILE_WRITE | FILE_CSV) ) ;
    }
    oF.WriteString ( "This,is,a,test" ) ;
    oF.WriteString ( "1This,2is,3a,4test" ) ;
    oF.Save (oF.Handle ( ) ) ;
    oF.Close (  ) ;
  }
 
Documentation on MQL5: Standard Constants, Enumerations and Structures / Input/Output Constants / File Opening Flags
  • www.mql5.com
Standard Constants, Enumerations and Structures / Input/Output Constants / File Opening Flags - Documentation on MQL5
Rashid Umarov
Admin
11993
Rashid Umarov  
See section File Functions:

For security reasons, work with files is strictly controlled in the MQL5 language. Files with which file operations are conducted using MQL5 means, cannot be outside the file sandbox.

There are two directories (with subdirectories) in which working files can be located:

  • terminal_path\MQL5\FILES\ (in the terminal menu select to view "File" - "Open the data directory");
  • the common folder for all the terminals installed on a computer - usually located in the directory C:\Documents and Settings\All Users\Application Data\MetaQuotes\Terminal\Common\.

To add comments, please log in or register