If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: how can i convert write() procedure to cout?

Before reaching for variable argument lists, look at the syntax for formatted output commonly used with output streams such as std::cout. The basic idea here is to overload operator<< such that a reference to the output stream is the left hand parameter and the object to be printed is the right hand parameter. Then, these calls are chained together by returning a reference to the same output stream.

You can do something similiar for your Console class' Write function, e.g., a user of the class might chain Write calls to write objects of different types to the console in sequence. Exactly how depends on what exactly you want to do and with what syntax.

The "convert it to cout" part is too vague: are you talking about implementing your Write function to write to std::cout?

Re: how can i convert write() procedure to cout?

Originally Posted by laserlight

Before reaching for variable argument lists, look at the syntax for formatted output commonly used with output streams such as std::cout. The basic idea here is to overload operator<< such that a reference to the output stream is the left hand parameter and the object to be printed is the right hand parameter. Then, these calls are chained together by returning a reference to the same output stream.

You can do something similiar for your Console class' Write function, e.g., a user of the class might chain Write calls to write objects of different types to the console in sequence. Exactly how depends on what exactly you want to do and with what syntax.

The "convert it to cout" part is too vague: are you talking about implementing your Write function to write to std::cout?

yes. because the prinf() is more complicated and i want be more simple
intead use '<<', my function uses ',' and '(',')' for open and close the function
but i don't understand how can i do a variable with any typebagavathikumar:

Re: how can i convert write() procedure to cout?

yes. because the prinf() is more complicated and i want be more simple

Where does prinf (printf?) come into the picture? You want to come up with something more simple than what? It almost sounds as if you think std::cout is used together with printf.

Originally Posted by Cambalinho

intead use '<<', my function uses ',' and '(',')' for open and close the function

Looking at your example in post #3, you effectively want variable length argument list syntax. Unfortunately, if I remember correctly, the variable length argument list feature does not cater to objects of class types that do not satisfy certain requirements.

Furthermore, if you are not adding anything over the standard conventions of output streams in C++, why bother? It sounds as if you are merely planning to change the syntax, and that is a Bad Thing because it means your library users have to learn yet another thing with no value added. The only thing you have going is the vague notion of something "more simple", but sorry this:

Code:

write( varname1, varname2, newline,...)

is not "more simple" than:

Code:

std::cout << varname1 << varname2 << '\n';

If you want to take a look a project that actually does add value, read up on Boost.Format.

Re: how can i convert write() procedure to cout?

Where does prinf (printf?) come into the picture? You want to come up with something more simple than what? It almost sounds as if you think std::cout is used together with printf.

Looking at your example in post #3, you effectively want variable length argument list syntax. Unfortunately, if I remember correctly, the variable length argument list feature does not cater to objects of class types that do not satisfy certain requirements.

Furthermore, if you are not adding anything over the standard conventions of output streams in C++, why bother? It sounds as if you are merely planning to change the syntax, and that is a Bad Thing because it means your library users have to learn yet another thing with no value added. The only thing you have going is the vague notion of something "more simple", but sorry this:

Code:

write( varname1, varname2, newline,...)

is not "more simple" than:

Code:

std::cout << varname1 << varname2 << '\n';

If you want to take a look a project that actually does add value, read up on Boost.Format.

ok... but i need build that function
(i'm building the console class for my new language... that's why i need 'rebuild' the cout)
can you advice me for correct that errors?
but can i create the 'cout'(with write keyword) in a class?

Re: how can i convert write() procedure to cout?

Using functions with variable number of arguments via the va_ set of macros is one of the more dusky corners of c++ inherited from c. I would strongly advise against using this mechanism if the result can be implemented some other way (eg function or operator overloading).

If you are using c++11 and really, really want functions with variable number of arguments, the answer is probably to use Variadic Templates.

Re: how can i convert write() procedure to cout?

Originally Posted by 2kaud

Using functions with variable number of arguments via the va_ set of macros is one of the more dusky corners of c++ inherited from c. I would strongly advise against using this mechanism if the result can be implemented some other way (eg function or operator overloading).

If you are using c++11 and really, really want functions with variable number of arguments, the answer is probably to use Variadic Templates.

But before you get bogged down in the detail of implementing these templates, think again if you really need this functinality and that what you want to do couldn't be done some other simpler way.

that tutorial is limited, the 1st argument is the master and tell us, indirectly, how many arguments received
i need use the write() like these:
write(var1, var2, "hello world")
the order i don't care, but i don't use strings or arguments for tell me the number of arguments.