473,810 Members | 3,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

file pointer reset of CArchive

50 New Member
Hello, I used below MFC code to read a file, but I need do that several times, how can I move the pointer to the beginning of file once again. Thank you!

CFile f;
CArchive ar(&f, CArchive::load) ;
...
while(ar.ReadSt ring(ptr))
{
...
}

//here should reset to the beginning of file

//re-read the file again
while(ar.ReadSt ring(ptr))
{
...
}
Aug 13 '08 #1
5 4926
arnaudk
424 Contributor
See CFile reference, in particular take a look at the various functions affecting the position within the file.
Aug 13 '08 #2
leejwen
50 New Member
See CFile reference, in particular take a look at the various functions affecting the position within the file.
Thank you! That's helpful
Aug 13 '08 #3
leejwen
50 New Member
Thank you! That's helpful
But why second "while" doesnt work? see below. (It seems the pointer is still at the end of file)

CFile f;
CArchive ar(&f, CArchive::load) ;
...
while(ar.ReadSt ring(ptr))
{
//work well
}

ar.Flush();
ar.GetFile()->SeekToBegin( );
ar.Flush();
while(ar.ReadSt ring(ptr))
{
//
}
Aug 13 '08 #4
arnaudk
424 Contributor
The thing is you're reading from a CArchive, not the file directly. Try to close and reopen the CArchive it before the second loop. Check the CArchive reference.
Aug 13 '08 #5
leejwen
50 New Member
play a small trick to finish that,

CFile f;
{
CArchive ar(&f, CArchive::load) ;
while(ar.ReadSt ring())
{
//
}
}
f.SeekToBegin() ;
{
CArchive ar(&f, CArchive::load) ;
while(ar.ReadSt ring())
{
//
}
}

Thank you!
Aug 14 '08 #6

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

Similar topics

5
4910
by: Sanyi | last post by:
I am having some trouble rereading a file for input. Here's the problem: I have a text file with some data (football scores) in its lines. First I read them line-by line to figure out how many lines it has. Afterwards I want to read them again, and this time do some processing. However I cannot make my program do this. I tried the following: ############################ #include <iostream>
2
2345
by: Asfand Yar Qazi | last post by:
Hello. Partly for learning purposes, I have written a smart pointer class. Could you please tell me what's wrong with it? (I know there's something wrong with it, but just not what!) Note that, as well as reference counting the stored pointer, it also has the ability to be declared for incomplete types (I think). I.e.: struct Incomplete;
12
2604
by: Woodster | last post by:
I currently have some code for an application that is running on Win32. I have tried to keep anything not directly gui related as separate as possible for portability reasons, including file access. Now has come the time to try and implement the program on a Windows CE platform. Problem is, that the MFC CArchive class uses an integer file pointer and calls to open, close etc and my file handling class is doing everything with FILE *, such...
5
3807
by: g18c | last post by:
I am trying to have a pointer to a member variable, however i will be deriving a number of classes from a base class. Whilst the code below works, i am wondering if there is a better way of doing this, or indeed if there are any traps i am missing. #include <iostream> class BaseClass { public:
2
2330
by: Claire | last post by:
I need to interface to an MFC CArchive file created with Visual Studio 6. I've found some online sample code to translate an archived string into C# I now need to read in and translate a CTime object. This is written to the file as 4 bytes. Can anyone tell me the structure please (It's a shame that Microsoft don't publish information on CArchive formats in support for conversion to the dotnet framework)
51
10513
by: Joe Van Dyk | last post by:
When you delete a pointer, you should set it to NULL, right? Joe
10
2093
by: pkirk25 | last post by:
while (1) { fgets(temp_string, MAXLEN, auctioneer_lua); /* check that we do ahve a valid data input file */ if (strstr(temp_string, "AuctioneerHistoryDB")) { /* this is a valid file */ printf("%s\n", temp_string); j = items_list(auctioneer_lua);
24
4462
by: Bill | last post by:
Hello, I'm trying to output buffer content to a file. I either get an access violation error, or crazy looking output in the file depending on which method I use to write the file. Can anyone help out a newbie? #include <stdio.h> #include <ctype.h> #include <string.h>
13
2081
by: Phil Bouchard | last post by:
I am currently writting a smart pointer which is reasonnably stable and I decided supporting allocators for completion because of its increase in efficiency when the same pool used by containers is shared. I was told the new standards are being finalized and I am hoping minor but important changes could be applied before anything else. To give a quick overview on the current status of this topic, you will find below the latest text...
0
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10379
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10124
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6882
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4334
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 we have to send another system
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.