c++ simple stream manipulation with ostream and istream? -


I'm looking for a solution, but I can not find what I want / want.

All I want to do, Stud :: passes a stream for the function of CF, which manilizes it. What I've used so far is a template function:

  template & lt; Typename T & gt; Zero printout (TA) {std :: cout & lt; & Lt; "Blubala" & lt; & Lt; A & lt; & Lt; Std :: flush; } Int main (int argc, char ** argv) {std :: stringstream str; Str & lt; & Lt; "Hello" & lt; & Lt; 1 + 4 & lt; & Lt; " Bye"; Printupdate & lt; & Gt; (Str.str ()); Return 0; }   

What do I like:

  printUpdate & lt; & Lt; "Hello" & lt; & Lt; 1 + 4 & lt; & Lt; " Bye";   

or

  std :: cout & lt; & Lt; Printupdate & lt; & Lt; "Hello" & lt; & Lt; 1 + 4 & lt; & Lt; " Bye";   

I was trying to:

  zero print offset (std :: istream & amp; a) {std :: cout & lt; & Lt; "Blubala" & lt; & Lt; A & lt; & Lt; Std :: flush; }   

But he gave me:

  Error: invalid type of type "zero" (std :: istream & amp;) {aka zero (std) :: basic_istream & lt; four & gt; & amp;)} a ???? And a ?? Const char [5] a ???? Operator for binary & lt; & Lt;?    

You can not output data to an input stream, just a good thing Do not do it. Change:

  Zero printupdate (standard :: eastim and a) {std :: cout & lt; & Lt; "Blubala" & lt; & Lt; A & lt; & Lt; Std :: flush; }   

to:

  zero printout (std :: ostream & amp; a) {std :: cout & lt; & Lt; "Blubala" & lt; & Lt; A & lt; & Lt; Std :: flush; }   

Note that the stream type change

Edit 1:
Also, you can not stream any stream at least std :: cout .
& lt; & Lt; A is a type of ostream .
cout stream does not like to feed other streams.

Change to:

  zero printUpdate (std :: ostream & amp; a) {static const std :: string text = "blabla"; Std :: cout & lt; & Lt; Text & lt; & Lt; Std :: flush; A & lt; & Lt; Text & lt; & Lt; Std :: flush; }   

Edit 2:
There is a need to pass a stream at the function that requires a stream.
You need a string to have a stream.
Try it out:

  void printUpdate (std :: ostream & outside, const std :: string & text) {std :: Cout & lt; & Lt; Text & lt; & Lt; Std :: flush; Outside & lt; & Lt; Text & lt; & Lt; Std :: flush; } int main (zero) {std :: ofstream my_file ("test.txt"); PrintAdadet (my_file, "Apples falls from the trees. \ N"); Return 0; }  If you want to function like chain items in the output stream, like the result from the function, the function must return the printable (streamable object), or the same output stream.  

Example:

  std :: ostream & amp; Fred (standard :: ostream and outside, const std :: string text) {outside < & Lt; "- Fred -" & lt; & Lt; Text; Return; } Ent Main (zero) {std :: cout & lt; & Lt; "Hello" & lt; & Lt; Fred ("World \ N!"); Return 0; }    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -