void getSize21() { ifstream wFile; wFile.open("log3.txt",ios::ate); if(!wFile.is_open()) { cout<<"Open log3.txt failed!"<<endl; } streampos size; size=wFile.tellg(); cout<<"Size="<<size<<endl; cout<<"Finished in getSize21() and now is "<<getTimeNow()<<endl; }
The key located at set ios::ate,ate stands for at end.
Then when size=wFile.tellg();
void getFileSize19() { streampos begin,end; ifstream rFile("log3.txt",ios::in); if(!rFile.is_open()) { cout<<"Open log3.txt failed!"<<endl; } begin=rFile.tellg(); cout<<"Begin is "<<begin<<endl; rFile.seekg(0,ios::end); end=rFile.tellg(); cout<<"End is "<<end<<endl; rFile.close(); cout<<"Size is "<<(end-begin)<<" bytes"<<endl; }
Similar Posts:
- C++ write and read file via fstream in ios::out,ios::in,ios::app mode
- [How to Solve]error: invalid array assignment
- [leetcode] 280. Wiggle sort
- C write and read file via FILE and open method in a+ or r mode
- How to Solve MySQL Errno:1782 Error
- [Solved] JMeter Generate the report of html Error
- LaTex Error:Unknown graphics extension:.eps (la…
- Solution to the error of ora-06550 pls-00103 when Django connects Oracle to run PLSQL statement
- [Solved] OpenCV 4 (C++) Error: “error: ‘CV_FOURCC’ was not declared in this scope”