Skip to ContentSkip to Footer
Start of content
- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - Linux
- >
- General
- >
- The file pointer can not come back when meet EOF?
General
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Latin America
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-09-2001 02:56 PM
03-09-2001 02:56 PM
The file pointer can not come back when meet EOF?
When I use lFileLength = IN.tellg(); to get the position of file stream and lster use
IN.seekg(lFilePosition); to relocate the pointor to old position, it OK unless the pointor does not reach EOF. If the pointor reach EOF, it never come back even use IN.seekg(lFilePosition); The compiler is g++ in Linux. Using other compiler, such as CC in SUNOS5.8 is OK.
Why?
IN.seekg(lFilePosition); to relocate the pointor to old position, it OK unless the pointor does not reach EOF. If the pointor reach EOF, it never come back even use IN.seekg(lFilePosition); The compiler is g++ in Linux. Using other compiler, such as CC in SUNOS5.8 is OK.
Why?
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-09-2001 03:31 PM
03-09-2001 03:31 PM
Re: The file pointer can not come back when meet EOF?
//When pointor reach EOF, you cannot get it back!!!!?????
#define MAX_LINE 500
#include
int main (){
long int lFileLength;
long int lFilePosition;
char sRaw[MAX_LINE];
int iLine;
ifstream IN;
IN.open("testfile.txt", ios::in, 0);
if (!IN){
cout<< "Cannot open validated file. \n";
return 0;
}
IN.seekg(0, ios::end);
lFileLength = IN.tellg();
IN.seekg(0, ios::beg);
while (!IN.eof()){ //the biggest loop
IN.getline(sRaw, 255);
if(IN.eof()){
break;
}
cout<
lFilePosition = IN.tellg();
iLine=0;
while(iLine<5 ){
if(IN.eof()){
break;
}
IN.getline(sRaw, MAX_LINE);
iLine++;
cout<<" "<
}
//return to the old position
IN.seekg(lFilePosition);
}
IN.close();
return 1;
}
#define MAX_LINE 500
#include
int main (){
long int lFileLength;
long int lFilePosition;
char sRaw[MAX_LINE];
int iLine;
ifstream IN;
IN.open("testfile.txt", ios::in, 0);
if (!IN){
cout<< "Cannot open validated file. \n";
return 0;
}
IN.seekg(0, ios::end);
lFileLength = IN.tellg();
IN.seekg(0, ios::beg);
while (!IN.eof()){ //the biggest loop
IN.getline(sRaw, 255);
if(IN.eof()){
break;
}
cout<
lFilePosition = IN.tellg();
iLine=0;
while(iLine<5 ){
if(IN.eof()){
break;
}
IN.getline(sRaw, MAX_LINE);
iLine++;
cout<<" "<
}
//return to the old position
IN.seekg(lFilePosition);
}
IN.close();
return 1;
}
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
End of content
United States
Hewlett Packard Enterprise International
Communities
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP