+ 5
How do I get the file size in c++?
I know how to open a file, but I don't know how to get the file size to terminate a while loop that reads every single character and uses it. I tried this: char ReadFile () { char look ; ifstream SLOPE_File (test.slope) ; while (len(SLOPE_File)) { SLOPE_File.get (look) ; } } Is that correct? Thanks!
4 odpowiedzi
+ 2
Use ios_base::ate and fstream::tellg().
If you want to go back to the start of the file, use fstream::seekg(0).
+ 4
Timon Paßlick
Thank you!
+ 3
Timon Paßlick
Yes, in the main.cpp file. With:
using namespace std;
+ 2
This is what I have done:
char look ;
char ReadFile (string fDir, string fName)
{
string file = fDir + "/" + fName + ".slope" ;
ifstream SLOPE_File (file) ;
while (SLOPE_File.get(look) ;
}