Questions tagged [seekg]

89 questions
0
votes
0 answers

How to overwrite a file after already open?

I'm having the following problem: my program opens a file and copy all its content to a vector. After that, i need to get back to the beginning of the file and rewrite the content in another order. I tried using clear and seekp, but it didn't…
user3735796
  • 191
  • 2
  • 2
  • 7
0
votes
1 answer

seekg() failing mysteriously

I have a 2884765579 bytes file. This is double checked with this function, that returns that number: size_t GetSize() { const size_t current_position = mFile.tellg(); mFile.seekg(0, std::ios::end); const size_t ret =…
Andreas Bonini
  • 44,018
  • 30
  • 122
  • 156
0
votes
2 answers

Problems using seekg in C++

I'm reading a file through a function like this: #include #include #include ... void readfile(string name){ string line; int p = 0; ifstream f(name.c_str()); while(getline(f,line)){ p++; } …
Zasito
  • 281
  • 1
  • 7
  • 17
0
votes
1 answer

fstream seeking: position stays at -1

I constructed a class for dealing in a certain file formal and it's constructor goes through the file and searches for the key information I need - the idea is characters are written on multiple lines, and I want to read the first character of every…
SJWard
  • 3,629
  • 5
  • 39
  • 54
0
votes
2 answers

read and write file in chunks of bytes in c++

I have searched for it everywhere, but I can not seem to understand how to use ios::cur. I need to read a whole file in chunks of 10 bytes, write those bytes into a buffer and then write that buffer into another file. For that I send the first 10…
Basilisk
  • 13
  • 1
  • 2
  • 6
0
votes
2 answers

Reading from a particular fill till the last line in C++

I have a text file with many lines. I want to store each line in a vector of strings. I want to read from the file until the last line is reached. I used the EOF function but it seems to store blank lines after the last line also. Here's a snippet…
Manmeet Saluja
  • 147
  • 1
  • 2
  • 6
0
votes
2 answers

Why seekg function doesn't work?

Here's the code: #include #include #include using namespace std; int main(int argc, char *argv[]) { string infile(argv[1]); ifstream fin(infile.data()); string var_name; char ch = fin.get(); cout << ch <<…
eaglesky
  • 730
  • 2
  • 13
  • 28
0
votes
1 answer

seekg invalid arguments?

I'm trying to use seekg for the first time. It says in the documentation it's arguments could be: istream& seekg ( streampos pos ); istream& seekg ( streamoff off, ios_base::seekdir dir ); From what I understood, 'streampos pos' could be an int? I…
John smith
  • 27
  • 1
  • 1
  • 5
0
votes
1 answer

cannot update a field of a record in a relative file, C++

After adding records in the relative file, I am trying to update one field (the balance) of a given record(client) that the user provide the account number. The update happens in the file, but it is not properly done. The output shows that the…
T4000
  • 231
  • 1
  • 7
  • 24
-1
votes
1 answer

Fast accessing file position in ifs() C++

Info: What is the best way to store a position in a txt file, close the file, and later open it at the same position using c++? I have a large text file that I need to parse in chunks and feed into some system. As of now, I load the file in the…
Sadikov
  • 127
  • 11
-1
votes
1 answer

How to correctly buffer lines using fread

I want to use fread() for IO for some reason (speed and ...). i have a file with different sized lines. by using a code like: while( !EOF ){ fread(buffer,500MB,1,fileName); // process buffer } the last line may read incompletely and we have to…
ameerosein
  • 523
  • 3
  • 16
-1
votes
1 answer

Create file using fstream if it doesn't exist that utilizes seekp/seekg?

fstream file(file_1.c_str(), ios::out | ios::in | ios::ate); //convert string to const char* Error if File does not exist. if ( ! file ) = true fstream file(file_1.c_str(), ios::out | ios::in | ios::app); //convert string to const char* using…
Need_Help
  • 19
  • 4
-1
votes
1 answer

Need help using seekg

I need to write a program that reads certain characters in a file. For example: all characters from beginning to end or in reverse order. How can I show all characters instead of just one? //This program reads a file from beg to end, end to beg,…
-3
votes
1 answer

How do I tell a program where to start reading a .txt file?

I want my program to be able to remember where it left off in a .txt file in order to proceed to the next input upon reiteration through a loop. For instance, a text file containing: Apples Bananas Oranges would be accessed through a function…
ntjess
  • 39
  • 2
1 2 3 4 5
6