473,473 Members | 1,906 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

seekg problem

3 New Member
Hello,
I wrote a code that deals with data files. Each file has a header. At sum stage when I use seekg or seekp it erases the header of the file.
What could be the cause of this?
naph
Jul 14 '07 #1
4 2376
weaknessforcats
9,208 Recognized Expert Moderator Expert
seekg() and seekp() do not write.

Something else is wrong. Do you have a code sample?
Jul 15 '07 #2
naph
3 New Member
seekg() and seekp() do not write.

Something else is wrong. Do you have a code sample?
it is a long class that deals with extenedhash files. data and bat. this is the function where i use seekg. after the seekg line i get a long line in my file until the seekg position.
void Extendhash::readBlock(block &dest, fstream &input, int block)
{
if(!input.is_open())
throw "readBlock(): Input file closed!";

// variables to hold the input data (identical to the variables in the block class)
char blockNumber[5] = {""};
char recordCount[3] = {""};
char blockType[2] = {""}; // "D": data, "B": b-a-t
char depth[5] = {""};
char nextBlock[5] = {""};
char empty[4] = {""};
char data[1000] = {""};

// move the read pointer to the desired block and read its data
input.seekg(block * BlockSize);
int temp = input.tellg();
input.read(blockNumber, 4);
input.read(recordCount, 2);
input.read(blockType, 1);
input.read(depth, 4);
input.read(nextBlock, 4);
input.read(empty, 3);
input.read(data, 999);

dest.setNumOfBlock(blockNumber);
dest.setBlockType(blockType);
dest.setDepth(depth);
dest.setRecordBlockCount(recordCount);
dest.setNextBlock(nextBlock);
dest.setData(data);
}
Jul 16 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
I assume these write to the file??
dest.setNumOfBlock(blockNumber);
dest.setBlockType(blockType);
dest.setDepth(depth);
dest.setRecordBlockCount(recordCount);
dest.setNextBlock(nextBlock);
dest.setData(data);
So to what file does dest write?? It wouldn't, by any chance, be the input file opened under another name and positioned at the beginning?
Jul 16 '07 #4
naph
3 New Member
I assume these write to the file??


So to what file does dest write?? It wouldn't, by any chance, be the input file opened under another name and positioned at the beginning?
somehow the problem has solved it self. must have been other problems i had effecting it.
thanks for the help anyway.
Jul 16 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Kapil Khosla | last post by:
Hi, I am trying to move the file pointer back to the original location, but not able to using seekg, can someone help ? Thanks, Kapil #include "stdafx.h" using std::cerr; using std::endl;...
1
by: wtnt | last post by:
Hello. I've searched all over and haven't seen another thread with this problem. Please bear with me as I try to explain. thanks. :) I have some programs that need to be cross-platform...
2
by: Brian Ronk | last post by:
I'm having a strange error. I have a Debian stable server and I'm using gcc 3.3, but it looks like I have 3.4 installed as well. I recently made a change to a program that takes data from two...
2
by: Assertor | last post by:
Hi, All. (VC++6.0) I found some strange thins when using getline() and seekg() of std::ifstream. After the file position of an open file was shift to the end of the file, seekg() did not...
1
by: pantatkau | last post by:
i am trying to use the seekg(offset, base) function to move the read position but cant seem to do it correctly. When i use tellg() to know if the seekg operation is successful or not , the tellg()...
3
by: nomad5000 | last post by:
Hi I'm trying to read a textfile and print it's content twice to the std::cout but it won't work the second time. I think it has something to do with the seekg(0) command but I don't know. here is...
4
by: jewel87 | last post by:
Hello, I have a problem in the following code: OutputFile.clear(); OutputFile.seekg(0); The compiler (Visual Studio) gives an error message: error C2039: 'seekg' : is not a member of...
12
by: Julian | last post by:
Hi, I am having problems with a function that I have been using in my program to read sentences from a 'command file' and parse them into commands. the surprising thing is that the program works...
1
by: fmufti | last post by:
I would like to check if the f_count is a valid position for seekg in the file or not. What I mean is if I pass a position to seekg and that does not exist in the file then e.g if...
2
by: geseeker | last post by:
Hi, i want to move the file pointer to the last 128th byte, so i can read the ID3V1 tag in an mp3 file. Here's my code to test the result of moving the file pointer: #include <iostream> #include...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.