I use this function to add a line to a file:
//use: addLineToFileCommon("line\n", "folder\\name.txt"); // shared=true, maxPrt=10 bool addLineToFileCommon(const string line, const string fName, const bool shared = true, const int maxPrt=10) { ResetLastError(); static int nErr=0; int fH; if ( shared ) fH = FileOpen(fName,FILE_READ|FILE_WRITE|FILE_BIN|FILE_COMMON|FILE_SHARE_READ|FILE_SHARE_WRITE); else fH = FileOpen(fName,FILE_READ|FILE_WRITE|FILE_BIN|FILE_COMMON); if (fH == INVALID_HANDLE ) { if (nErr<maxPrt) Print("Common-File: >"+fName+"< Open FAILED err:",_LastError); return(false);} FileSeek(fH,0,SEEK_END); FileWriteString(fH, line, StringLen(line) ); FileClose(fH); if (_LastError<2) return(true); return(false); }
and this to read the whole file into an array of the lines:
int readAllLines( const string fName, string &l[], ushort sepLine='\n') { // alternative to FileOpen uchar Bytes[]; return( FileLoad(fName, Bytes) ? StringSplit(CharArrayToString(Bytes), '\n', l) : 0); }
With some (not tested!!) changes.
NFONSECA:
I am creating a code to create and read a TXT file, but for some reason when I try to read it, not works.
Some help will be good.
Thanks in Adavance.
Some help?

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I am creating a code to create and read a TXT file, but for some reason when I try to read it, not works.
Some help will be good.
Thanks in Adavance.