Quantcast
Channel: Comments on: 13.7 — Random file I/O
Browsing all 28 articles
Browse latest View live

By: Alex

Hmmm, that is interesting about seekg(0, ios::cur) not working for you. It worked fine for me, but maybe it is being optimized away in your case as you suggest. I added a short blurb about tellg() and...

View Article



By: Learn C++ - » 14.1 — Function templates

[...] 2007 Prev/Next Posts « 13.7 — Random file I/O | Home | 14.2 — Function template instances » Friday, April 18th, 2008 at 4:54 [...]

View Article

By: dekaya

I modified your code slightly to get it to work on my win2k machine. using dev-cpp I added : #include <fstream>// *** added for fstreams using namespace std; //moved outside of main //and finally...

View Article

By: Ebrahim

Hello why this code is true? #include #include using namespace std; int main() { int b[4]={1,1,5,1}; int c[4]={0}; fstream A("File.txt",ios::binary|ios::in|ios::out); if(!A) { return 1; } A.write((char...

View Article

By: Ebrahim

Hello why this code is true? #include<iostream> #include <fstream> using namespace std; int main() { int b[4]={1,1,5,1}; int c[4]={0}; fstream A("File.txt",ios::binary|ios::in|ios::out);...

View Article


By: Tobi

Thanks, was wondering why this code snippet didn’t work for me but with binary mode it worked flawlessly:)

View Article

By: Casey

Is it possible to pass fstream objects as parameters? I am writing a simple function that calculates the size of a file stream passed to it. Here is the code. //Obtain the size of the file without...

View Article

By: Casey

I figured out my problem. The ios namespace lives inside std, so to use ios, I must also use std. My fstream parameters were being declared outside of their scope. Man, this stuff gets confusing!

View Article


By: 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


By: 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 Article

By: Grant

I think you can also use: iofile.seekg( iofile.tellg(), ios::beg); Grant

View Article

By: 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 Article

By: Alex

Fixed. Thanks!

View Article


By: 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 Article

By: 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 Article


By: Lokesh

#typo "One other bit of trickiness: Unlike istream," -> ifstream

View Article

By: Alex

Fixed, thanks!

View Article


By: 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 Article

By: 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 Article

By: 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 Article
Browsing all 28 articles
Browse latest View live




Latest Images