•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 429,791 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,806 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 8252 | Replies: 1
![]() |
•
•
Join Date: Feb 2005
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
Hi,
I have the following piece of code. I do the following here
1)open a file.
2) Print the filepointer positon . I get 0
3)Read the file in a while loop till i reach the end
4)close the file
5)Open the same file
6) Print the file pointer position I get -1.( I expect 0 here)
Can anyone let me know the reason for this error and how is it possible to avoid this.
Thanking you in advance
Samarth
I have the following piece of code. I do the following here
1)open a file.
2) Print the filepointer positon . I get 0
3)Read the file in a while loop till i reach the end
4)close the file
5)Open the same file
6) Print the file pointer position I get -1.( I expect 0 here)
Can anyone let me know the reason for this error and how is it possible to avoid this.
Thanking you in advance
Samarth
#include <fstream>
#include <iostream>
using namespace std;
int OpenFile(fstream &fileHandle, char * fileName)
{
cout << "Opening File" << endl;
int success = true;
// Open the file and read the data
fileHandle.open(fileName, ios::in|ios::binary);
// Check if the file is present
if (!fileHandle.is_open())
{
// File is not present. Log the information
cout << "OpenFile::Error opening file "<< endl;
success = false;
}
return success;
}
int ReadFile(char *buf, fstream &file)
{
while(!file.eof())
{
file.read(buf, 1024);
}
}
int main()
{
fstream file;
OpenFile(file, "1.mpg");
cout << "tellg " << file.tellg()<< endl;
char buf[1024];
ReadFile(buf,file);
file.close();
//file = new ifstream();
OpenFile(file, "1.mpg");
cout << "tellg " << file.tellg()<< endl;
return 1;
} Last edited by alc6379 : Feb 23rd, 2005 at 5:16 pm. Reason: added [code] tags
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- File Pointer in C (C)
- ifstream file (C++)
- file pointer increament (C)
Other Threads in the C++ Forum
- Previous Thread: Question about Functions
- Next Thread: c++ homework


Linear Mode