473,396 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

file pointer reset of CArchive

50
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.ReadString(ptr))
{
...
}

//here should reset to the beginning of file

//re-read the file again
while(ar.ReadString(ptr))
{
...
}
Aug 13 '08 #1
5 4895
arnaudk
424 256MB
See CFile reference, in particular take a look at the various functions affecting the position within the file.
Aug 13 '08 #2
leejwen
50
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
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.ReadString(ptr))
{
//work well
}

ar.Flush();
ar.GetFile()->SeekToBegin();
ar.Flush();
while(ar.ReadString(ptr))
{
//
}
Aug 13 '08 #4
arnaudk
424 256MB
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
play a small trick to finish that,

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

Thank you!
Aug 14 '08 #6

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

Similar topics

5
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...
2
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...
12
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...
5
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...
2
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...
51
by: Joe Van Dyk | last post by:
When you delete a pointer, you should set it to NULL, right? Joe
10
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 */...
24
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...
13
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.