By: Alex
Generally, adding anything to or removing anything from a file directly is a bad idea. You’re better off reading the contents of the file into memory, modifying them in memory, and then writing them out.
View ArticleBy: Kausthub
Hi Alex You haven’t taught how to delete a record in a file having classes or structures
View ArticleBy: LeoNardo
hii I ‘m confusing about How to modify the content in file by random access
View ArticleBy: Alex
The best way to do this is either to: 1) Read the contents of the file into memory, modify the content in memory, and write them back out, or 2) While you’re reading the contents of the file, write...
View ArticleBy: RWDavid
Hi Alex 🙂 Is there anyway to write into a file where it does not overwrite the existing characters? For example, you search for every vowel in the text file and you want to insert a ‘$’ after the...
View ArticleBy: Alex
I don’t actually know. It must have something to do with the way the streams are implemented, but I don’t have enough in depth knowledge on that topic to say.
View ArticleBy: Alex
It’s generally a bad idea to try to add/delete content from the middle of a file. For this kind of thing, it’s easier to either: 1) Read the whole file into memory, skipping the content you want to...
View ArticleBy: Sameeha Basha
Hi, Why is it necessary to do a seek operation in order to switch between read and write?
View ArticleBy: Hannah
Hi, is it possible to delete the contents of a file between locations A and B? I’m assuming that would be more difficult than overwriting, because we’re changing the location of the remaining content?
View ArticleBy: Alex
Typos fixed. It looks like some compilers have a buggy implementation of seekg() and tellg() when used in text mode. I’ve added a note about trying binary mode in this case.
View ArticleBy: Kodnot
First of all, a few minor typos: 1. Before the first big example: should be "Here’s" instead of "Heres"; 2. In "Reading and writing a file at the same time using fstream": "…and changes the any vowels...
View ArticleBy: Alex
To read a single line, use getline(). For what you want to do, I don’t think you need to seek by line. Just parse the entire database file upon load (using getline()), make your modifications to it in...
View ArticleBy: Aaron
What do I do if I want to read/write a single line? Is there a way to seek by line, rather than by bytes? I want to write a database file that contains variable length entries, reads them into an array...
View ArticleBy: Matt
Typo ("it’s" should be "its"): * "- that is, skip around to various points in the file to read it’s contents." * "We’re going to write a program that opens a file, reads it’s contents, and changes the...
View ArticleBy: loift
I need to do many manipulations on a file on a bit level. Is there a better way to do this than: (1)open the file in input mode (2)open a second file in output mode (3)read the input file as a string...
View ArticleBy: paras
hi..I want to find whether a string is present or not in a file which i have already written and its contents are being displayed…can someone help me with the code…
View Article