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 ArticleBy: 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 ArticleBy: 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 ArticleBy: 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 ArticleBy: 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 ArticleBy: Tobi
Thanks, was wondering why this code snippet didn’t work for me but with binary mode it worked flawlessly:)
View ArticleBy: 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 ArticleBy: 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 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 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: 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: 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: 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: 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
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: 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
More Pages to Explore .....