pos_type - How to define it ?

R

Rakesh Sinha

Hello,
I am writing this application for which I need to determine the file
size.
My code looks roughly as follows.


#include <fstream>
#include <iostream>

using std::ifstream;

ifstream fp;
fp.open("myfile", ios::binary);

ifp.seekg(0, ios::end);
pos_type length = ifp.tellg();

//Process with length

std::cout << "Length of file " << length << std::endl;

My problem is where is pos_type defined ? I can make an approximation
like unsigned long instead of it to get around , but I would not like
to do that.

I referred to the C++ 2003 standards and here is what I had found it
then.

[lib.ios] 27.4.4

namespace std {
..
class basic_ios : public ios_base {
public:
// Types:
typedef typename traits::pos_type pos_type;
};
}

How would I use this type in my program ?
 
D

David Harmon

On 18 Dec 2004 03:00:23 -0800 in comp.lang.c++, "Rakesh Sinha"
ifp.seekg(0, ios::end);
pos_type length = ifp.tellg();

Should be:
ios::pos_type length = ifp.tellg();

or
std::ios::pos_type length = ifp.tellg();
 
J

Jonathan Turkanis

David said:
On 18 Dec 2004 03:00:23 -0800 in comp.lang.c++, "Rakesh Sinha"


Should be:
ios::pos_type length = ifp.tellg();

or
std::ios::pos_type length = ifp.tellg();

Also note that pos_type (which is usually just std::streampos) is not an
integral type, but is convertible to one.

Jonathan
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top