| | |
C++: ifstream file pointer not getting reset
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2005
Posts: 2
Reputation:
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
C++ Syntax (Toggle Plain Text)
#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 6:16 pm. Reason: added [code] tags
![]() |
Similar Threads
- i m unable to move file pointer to the begining of file ??? (C++)
- File Pointer in C (C)
- ifstream file (C++)
- file pointer increament (C)
Other Threads in the C++ Forum
- Previous Thread: Have trouble with a dijkstra program
- Next Thread: Need help with task!!
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





