what diffierent between ios_base and ios ?

7

77123036

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

int main()
{
fstream inOut( "copy.out", ios_base::in|ios_base::app );
int cnt=0;
char ch;
inOut.seekg(0);
while ( inOut.get( ch ) )
{
cout.put( ch );
cnt++;
if ( ch == '\n' )
{
ios_base::pos_type mark = inOut.tellg();
/*here is an error , but if replace with
"ios::pos_type mark = inOut.tellg();"
it will work well .
can you tell me why?
*/
inOut << cnt << ' ';
inOut.seekg( mark );
}
}
inOut.clear();
inOut << cnt << endl;
cout << "[ " << cnt << " ]\n";
system("pause");
return 0;
}
 
H

Howard

ios_base::pos_type mark = inOut.tellg();
/*here is an error , but if replace with
"ios::pos_type mark = inOut.tellg();"
it will work well .
can you tell me why?

Because pos_type is a typedef within ios (defined in the ios standard
header, as _Traits::pos_type), not a member of the ios_base class. The
ios_base members are things like in, out, failbit, etc, not the "types" such
as pos_type, int_type, etc.

You can look them up in the headers for yourself, if you're interested.

-Howard
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top