my book says it is ok define
ostream& operator<<(ostr eam& (*p)(ostream ))
{ return (*p)( *this); }
ostream& endl(ostream& o)
{o.put('\n'); o.flush();}
but seems compiler says it is not correct because "<<" needs 2
arguments, so i wrote
ostream& operator<<(ostr eam& ostr, ostream& (*p)(ostream& ))
{ return (*p)( ostr ); }
ostream& endl(ostream& o)
{o.put('\n'); o.flush();}
and the compiler compile and run it when i write
cout << "jfjfjfj" << endl;
But i have some doubit. is the last right?
then i have not good understanding for objects ostream "ios" flags
"internal, uppercase". What is their purpose?
for istream "ios" what is the pourpose of
"left, right, internal, showbase, showpoint, uppercase, showpos,
scientific, fixed, "? 5 1576
ax wrote: my book says it is ok define
ostream& operator<<(ostr eam& (*p)(ostream )) { return (*p)( *this); }
I hope the book also says that it's OK to define it *only* as
a *member* of 'ostream'. Otherwise, what's "this" doing there?
ostream& endl(ostream& o) {o.put('\n'); o.flush();}
but seems compiler says it is not correct because "<<" needs 2 arguments, so i wrote
ostream& operator<<(ostr eam& ostr, ostream& (*p)(ostream& )) { return (*p)( ostr ); }
OK.
ostream& endl(ostream& o) {o.put('\n'); o.flush();} and the compiler compile and run it when i write cout << "jfjfjfj" << endl;
But i have some doubit. is the last right?
Seems fine. If it compiles and does what you need, what could be
the problem? B-)
then i have not good understanding for objects ostream "ios" flags "internal, uppercase". What is their purpose?
What does your favourite C++ book have to say about them? Are
you reading Kuehl and Langer's book on streams?
for istream "ios" what is the pourpose of "left, right, internal, showbase, showpoint, uppercase, showpos, scientific, fixed, "?
Get a good book that describes streams. Angelika Langer and Klaus
Kreft published one several years back, basically a textbook on C++
streams (ISBN: 0201183951).
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
* ax: my book says it is ok define
ostream& operator<<(ostr eam& (*p)(ostream )) { return (*p)( *this); }
Which book is that?
This could be a member function.
ostream& endl(ostream& o) {o.put('\n'); o.flush();}
but seems compiler says it is not correct because "<<" needs 2 arguments, so i wrote
ostream& operator<<(ostr eam& ostr, ostream& (*p)(ostream& )) { return (*p)( ostr ); }
ostream& endl(ostream& o) {o.put('\n'); o.flush();} and the compiler compile and run it when i write cout << "jfjfjfj" << endl;
But i have some doubit. is the last right?
No. You need to return a reference to the 'o' argument. Also, it's not
a good idea to use the same names as things in the std namespace.
then i have not good understanding for objects ostream "ios" flags "internal, uppercase". What is their purpose?
I don't think the first is standard, although it could be. The second
sounds like a standard one. Look them up in your /documentation/.
for istream "ios" what is the pourpose of "left, right, internal, showbase, showpoint, uppercase, showpos, scientific, fixed, "?
Whether this is HOMEWORK or not, look them up in your /documentation/.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
On Thu, 29 Jun 2006 16:31:03 +0200, "Alf P. Steinbach"
<al***@start.no > wrote: * ax: my book says it is ok define
ostream& operator<<(ostr eam& (*p)(ostream )) { return (*p)( *this); } Which book is that?
This could be a member function.
if i have the
class X{
public:
X(){}
~X(){}
friend int f(X, int);
friend ostream& operator<<(ostr eam& , X& );
X& operator=(X&);
X& g(int, X&);
};
"member functions" for class X are all functions for the class X?
(X() ~X(), f, <<, =, g)
or they are there only "=", "g"? ostream& endl(ostream& o) {o.put('\n'); o.flush();}
but seems compiler says it is not correct because "<<" needs 2 arguments, so i wrote
ostream& operator<<(ostr eam& ostr, ostream& (*p)(ostream& )) { return (*p)( ostr ); }
ostream& endl(ostream& o) {o.put('\n'); o.flush();} and the compiler compile and run it when i write cout << "jfjfjfj" << endl;
But i have some doubit. is the last right?
No. You need to return a reference to the 'o' argument. Also, it's not a good idea to use the same names as things in the std namespace.
return o;
ok i forgot to write it in the last endl (i copied the one of the book
and not the one in my code)
then i have not good understanding for objects ostream "ios" flags "internal, uppercase". What is their purpose?
I don't think the first is standard, although it could be. The second sounds like a standard one. Look them up in your /documentation/.
for istream "ios" what is the pourpose of "left, right, internal, showbase, showpoint, uppercase, showpos, scientific, fixed, "?
Whether this is HOMEWORK or not, look them up in your /documentation/.
what meaning is to define a "right" indentation for an input stream?
the same for showbase
is it the meaning: prog tell me it wants a hex value and i write 9 and
it doesn't accept it because the input stream has in its flag
"showbase" on?
On Thu, 29 Jun 2006 10:27:56 -0400, "Victor Bazarov"
<v.********@com Acast.net> wrote: ax wrote: my book says it is ok define
But i have some doubit. is the last right? Seems fine. If it compiles and does what you need, what could be the problem? B-)
my good C++ compiler allows all i imagine and all seems goes right
but i would like some feedback from humans because i see that everyone
use template "class <etc>" but i don't understand well, and don't
understand why ( because it seems i have all that i need without them) then i have not good understanding for objects ostream "ios" flags "internal, uppercase". What is their purpose?
What does your favourite C++ book have to say about them? Are you reading Kuehl and Langer's book on streams?
no. i like the book i read for istream "ios" what is the pourpose of "left, right, internal, showbase, showpoint, uppercase, showpos, scientific, fixed, "?
Get a good book that describes streams. Angelika Langer and Klaus Kreft published one several years back, basically a textbook on C++ streams (ISBN: 0201183951).
basically i reinvent the hot water and so i write the ostream,
istream, strstram classes (but they are different) so i would question
why the use of these flags in an input stream
V
thank you
On Thu, 29 Jun 2006 19:53:36 +0200, "ax" <aa@aa.aaa> wrote: for istream "ios" what is the pourpose of "left, right, internal, showbase, showpoint, uppercase, showpos, scientific, fixed, "?
Whether this is HOMEWORK or not, look them up in your /documentation/.
what meaning is to define a "right" indentation for an input stream? the same for showbase
is it the meaning: prog tell me it wants a hex value and i write 9 and it doesn't accept it because the input stream has in its flag "showbase" on?
so is there no answer? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: rwawryk |
last post by:
Hi,
Does anybody know how to implement parametrized stream operator (such as
setw, setfill)? I need to put into the stream variable of type char* without
terminating NULL. It would be great if I had the manipulator which allows to
determine maximum number of characters ( let's assume maxw( char* str, int
maxlen ) ).
example:
cout << maxw("Crocodile", 5 );
|
by: Riku Jarvinen |
last post by:
Hi everyone,
I asked another question regarding this same subject about a week ago. See
thread:
http://groups.google.fi/group/comp.lang.c++/browse_frm/thread/cc57b579d6832732/530bae667a479add#530bae667a479add
So, the basic idea is to have a compact logger class which can be used like
the std::cout stream and add extra functionality to it (line numbering, some
output counters etc.).
|
by: stoptv |
last post by:
Hello group, this is my dilemma:
------------------------------------------------------------------------
#include <iostream>
using namespace std;
// a regular manipulator
ostream & hello( ostream & os ) { return os << "regular: hello"; }
|
by: Peteroid |
last post by:
In the same spirit as setw( ) and setprecision( ), is there a stream
manipulator that will fill in closing-zeroes on those fractions with a given
setprecision( )?
For example, if setprecision(3) is used, I want '1' to be displayed as
"1.000", '1.2' to be displayed as "1.200", '1.23' to be displayed as
"1.230", '1.234' to be displayed as "1.234", and '1.2345' to be displayed as
"1.234" (or the rounded version "1.235" is ok too).
Thanx...
|
by: jack |
last post by:
I have a class which overloads the insertion operator '<<' for every
type that ostream handles. I do this so that I can use my class a
direct replacement for cout and cerr where the insertion syntax is
used. The reason for this is that I have a log file class that needs
to know how many lines have been written. When the line exceeds a
certain number, I need to close the log file, and open a new one.
I would like to be able to track...
| |
by: John Friedland |
last post by:
'printf' has a '%a' conversion for floating-point output:
For example, printing '123456' with "|%13.4a|" produces
| 0x1.e240p+16|
I've looked through Josuttis and the header files, but I can't find
any flags or manipulators that could handle this. Is this possible
with stream I/O?
|
by: Colloid Snake |
last post by:
Hello,
I was attempting to configure log4cpp to monitor some logs on my *nix box, and when I run 'make' I get this error message:
# make
g++ -DHAVE_CONFIG_H -I. -I. -I../include -I../include -g -02 -Wall -Wno-unused -pedantic -MT FileAppender.lo -MD -MP -MF .deps/FileAppender.Tpo -c FileAppender.cpp -fPIC -DPIC -o .libs/FileAppender.o
../include/log4cpp/Manipulator.hh:29: error: extra ';'
make: *** Error 1
|
by: barcaroller |
last post by:
When I use an iostream manipulator in a cout statement, it seems to affect
all subsequent cout statements.
cout << x << endl; // dec by default
cout << hex << x << endl; // hex
cout << x << endl // still hex
Is there a way I can have manipulators affect only the "current" cout
statement?
|
by: Dan Smithers |
last post by:
I want to write my own class derived from the ostream class.
I have been getting errors with my templates:
First, I get an error writing a nested template. If I leave the function
definition inside template class definition (commented out at //1) then
it compiles and runs fine, but if I declare and define the function
separately (at //2).
Is the following syntax supported by g++?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |