 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
77123036@163.com Guest
|
Posted: Wed Jun 15, 2005 10:28 am Post subject: what diffierent between ios_base and ios ? |
|
|
#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;
}
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Llewelly Guest
|
Posted: Wed Jun 15, 2005 10:47 pm Post subject: Re: what diffierent between ios_base and ios ? |
|
|
"77123036 (AT) 163 (DOT) com" <77123036 (AT) 163 (DOT) com> writes:
| Quote: | #include <iostream
#include
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;
}
|
ios is a typedef for basic_ios
basic_ios<> .
pos_type is dependent on the traits of the char type;
basic_ios<char>::pos_type and basic_ios<wchar_t>::pos_type are
potentially different types.
Since pos_type depends on the char type, and ios_base is independent
of char type, pos_type was not made a member of ios_base.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Albrecht Fritzsche Guest
|
Posted: Wed Jun 15, 2005 11:03 pm Post subject: Re: what diffierent between ios_base and ios ? |
|
|
template <class Elem, class Tr = char_traits
class basic_ios : public ios_base
{ ... };
and
typedef basic_ios<char, char_traits ios;
So, as you easily can see, both classes aren't the same. While the
std::ios_base is a non-template base class defining several flags,
types, ... is std::ios already char centric.
Since pos_type is defined in ios everything is ok - you should check a
C++ reference next to your place!
Ali
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ryan Gallagher Guest
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|