Questions tagged [seekg]

89 questions
1
vote
2 answers

seekg, relative or absolute position?

I need to read an array from a file. The array is not ordered continuously in the file, have to jump "offset" bytes to get the next element. What is more efficient, assuming that I read a very large file. 1) Use an incremental relative position. 2)…
Barak
  • 41
  • 4
1
vote
1 answer

Difficulty using file.seekg() (C++)

The following code only prints the file once: #include #include using namespace std; int main(int argc, const char *argv[]) { ifstream infile; infile.open("in", ios::binary); char c; while (infile.get(c)) …
James Jenkinson
  • 1,563
  • 2
  • 16
  • 33
0
votes
1 answer

seekg and tellg miscompatibility

I am writing a C++ console application. After creating an Matrix with size(int) rowSize and columnSize, I wanted to write the letters in text file to matrix, but while loop never runs because reader's location is -1, and I couldn't take it to 0. Any…
Yagiz
  • 1,033
  • 2
  • 21
  • 47
0
votes
1 answer

"seekg identifier not found"

I have a program called main: #include #include using namespace std; #include"other.h" int main() { //do stuff } and then other.h: char* load_data(int begin_point,int num_characters) { seekg(begin_point); char*…
user98188
0
votes
1 answer

seekg does not work after while(file.good()) {....}

I'm fairly perturbed that the below does not appear to work. while(myfile.good()) { myfile.get(holdc); .................... } //does not work myfile.seekg(0); myfile.read(buffer,5); sentence.push_back(buffer); cout <<…
VSB
  • 232
  • 1
  • 4
  • 13
0
votes
2 answers

tellg returning negative value after using getline and seekg

I am needing to parse through a text file and output the vowels within this textfile line by line into a separate file. This all needs to be done using one filestream at a time. I open the input stream using fstream ios:: in & ios::binary, read in…
0
votes
0 answers

seekg() before each .get() call VS seekg() before for loop

I am just trying to read simple text file with ifstream. Suppose my text file looks like this (I don't know how to properly format it here, so here is how I wrote it notepad): a\tb\nc\t\d\n Output from reading text file using .seekg() before each…
user859v
  • 1
  • 1
  • 1
0
votes
0 answers

Looping with seekg() is not behaving as expected

I'm getting behavior with seekg() that I don't understand. I avoid the C++ stream libraries as much as possible, so I'm sure I'm just missing something simple. The problem happens when calling seekg() as an index into the file. I would expect it…
Rez Bot
  • 13
  • 1
  • 2
0
votes
1 answer

seek from end of a istringstream fails

Here is a minimalist code : #include #include #include int main () { std::string str = "spam" ; std::istringstream isz( str ) ; isz.seekg( 1,std::ios_base::beg ) ; std::cout << isz.fail() ; …
Captain'Flam
  • 479
  • 4
  • 12
0
votes
1 answer

seekg() seeminlgy skipping characters past intended position C++

I've been having an issue with parsing through a file and the use of seekg(). Whenever a certain character is reached in a file, I want to loop until a condition is met. The loops works fine for the first iteration but, when it loops back, the file…
Idalas
  • 51
  • 8
0
votes
1 answer

seekg after reading to the end of the file

I'm trying to use the code below on the ifstream twice - before I read anything from the file, and after I read to the end of it (using readline()). m_hexFile->m_ifsteam->seekg(0, m_hexFile->m_ifsteam->ios_base::end); test1 =…
user3007875
  • 123
  • 7
0
votes
0 answers

Several input streams vs one input stream with seekg

I have a large (text) file that is divided into d "chunks". The user can read the next line from either of these chunks - the order is not specified. The file is not changed in the process. There are two obvious solutions: Maintaining d input…
mike
  • 75
  • 2
0
votes
0 answers

reading and writing to a file with fstream

bool remove_vowels(const std::string& file_name) { std::fstream fs{ file_name , std::ios_base::in | std::ios_base::out }; if (!fs) { std::cout << "Error file not open"; return false; } char in{}; while (fs >> in) { …
user12623797
0
votes
0 answers

After writing binary file and reading a record (an object) from the binary file, enum type last attribute of the record is NULL ( default value)

I'm trying to write a C++ code that read from a text file, write all the contents into a binary file, and read a record from the binary file.To hold records, I created a Student class that one of its attribute is enum type.I read from text file…
Denisa
  • 125
  • 4
  • 16
0
votes
1 answer

Cant understand how to use seekg tellg to achieve the following result

As part of a larger program, my task is to read each line of an input file and store the index offset to each line. Later given all the index offsets, I want to be able to go to that position in the file directly and print the line corresponding to…
batwing
  • 19
  • 5