How can I get the size of a ASCII file?

A

alex

HI,all:
I use ofstream of stl to manange a file, but how can I get size of
the file?

// open file
std::eek:fstream * log = new std::eek:fstream( "test.log" );
// get size
???
 
S

Stu

alex said:
HI,all:
I use ofstream of stl to manange a file, but how can I get size of
the file?

// open file
std::eek:fstream * log = new std::eek:fstream( "test.log" );
// get size
???

Simple, you just opened it for output and truncated it, so the file size is
zero...


Stu
 
A

alex

I think I make a mistake.
// Fix...
std::eek:fstream * log = new std::eek:fstream( "test.log",ios::app|ios::eek:ut
);
 
H

hacker++

alex said:
I think I make a mistake.
// Fix...
std::eek:fstream * log = new std::eek:fstream( "test.log",ios::app|ios::eek:ut
);

Hint: It's possible to randomly select your position in the file and
know your current positon at any time.
 
S

shanemjtownsend

#include <iostream>
#include <fstream>
using namespace std;

ofstream file("f:\\test.log",ios::app|ios::eek:ut );
file << "Hello World"; // push out some crap
file.seekp(0,ios::end); // seek end of file
ios::pos_type pos = file.tellp(); // get current position
cout << pos;
file.close();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top