k.shabordin Posted August 1, 2012 Posted August 1, 2012 This solution is work. But I'm think that is not rational. I would some advises. File file = new File(filename, "rb"); if(!file.isOpened()) log.error("can't open file %s\n",filename); else { string sourcecode = ""; while(file.tell() < file.getSize()) sourcecode += format("%c",file.getc()); log.message("body : \n%s\n",sourcecode); file.close(); }
ulf.schroeter Posted August 1, 2012 Posted August 1, 2012 You are opening your text file in binary mode ("rb"), try text mode instead ("r") File file = new File(filename, "r"); Maybe you could also use File base class function Stream::gets() instead of character-wise reading.
frustum Posted August 2, 2012 Posted August 2, 2012 Ulf is right, except for that "rb" file option is better than "r" because this is more portable across different OS. Windows skips '\r' symbol on reading and automatically adds a '\r' symbol after '\n' on writing with "w" opening mode.
Recommended Posts