C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

what diffierent between ios_base and ios ?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
77123036@163.com
Guest





PostPosted: Wed Jun 15, 2005 10:28 am    Post subject: what diffierent between ios_base and ios ? Reply with quote



#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





PostPosted: Wed Jun 15, 2005 10:47 pm    Post subject: Re: what diffierent between ios_base and ios ? Reply with quote



"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





PostPosted: Wed Jun 15, 2005 11:03 pm    Post subject: Re: what diffierent between ios_base and ios ? Reply with quote



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





PostPosted: Wed Jun 15, 2005 11:05 pm    Post subject: Re: what diffierent between ios_base and ios ? Reply with quote

check out the dinkumware reference for your answer:
http://www.dinkumware.com/manuals/reader.aspx?b=p/&h=ios.html


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.