Gord P 14 Posted February 29 I am updated an older C++Builder program. In it I use ifstream and ofstream for reading and writing text files, which then get parsed to extract various pieces of data. It works well enough but I wonder if I should be using TFileStream going forward. What are the advantages, if any, of using TFileStream? Share this post Link to post
Gord P 14 Posted February 29 I came across this article by Yilmaz Yoru on the Embarcadero C++Builder Community site: How To Read And Write Text Files In A Modern C++ App - March 28, 2022 In the article he only talks about ofstream and ifstream. No mention of TFileStream. However, in an article two years earlier (Windows File Operations in Modern C++) he does seem to promote TFileStream. I guess there is no real must-do way. I suppose sticking with the fstream methods is more portable. Share this post Link to post
Roger Cigol 107 Posted February 29 "Which is the best way?" questions in C++ are always tricky! The language has evolved so much (and continues to do so). We C++ Builder users have the added complication of the use of the VCL or FireMonkey functions (that come from the Delphi RTL). How important it is to keep your code portable is certainly one question to consider. Re: text files : also take into account encoding possiblities - if you need to anticipate different encodings then the VCL support is often the easiest route. I tend to use TStringList as the store and then the LoadFromFile() and SaveToFile() functions. 1 Share this post Link to post
Gord P 14 Posted February 29 Yes I recognize asking which is the best way can be tricky and subjective. I was just trying to make sure I wasn't using something that was generally considered obsolete, and as far as I can tell it isn't. Thanks for your comment and good point on encoding. Share this post Link to post