Assigning cout() to a variable


I am attempting to assign a cout statement to a (class member)variable with great difficulty. I would be grateful for any assistance available.

I am using the Dev C++ 4.9.9.2 compiler

1
2
3

  rank.First = cout <<weight << ("  pounds" )<< barSize << ("mm  Diameter Bars.");

Sorry but what are you trying to do? If you was able to assign it to a variable what would the variable contain or be able to do?
What is the type of rank.First?
cout is an object of type iostream.
What is it that you expect to be assigned?

You might try using stringstream:
http://www.cplusplus.com/reference/sstream/stringstream/

1
2
3
4
5
6
7
#include <sstream>

stringstream ss;
string temp;

ss <<weight << ("  pounds" )<< barSize << ("mm  Diameter Bars.");
temp = ss.str();





cout is an object of type iostream.

ostream

If it was iostream there would be no need for cin since it would be input and output.
Last edited on
std::cout is of type std::ostream.
http://www.cplusplus.com/reference/iostream/cout/

Also, std::ostream is a move-only type, so any assigning will either use a reference or a pointer to std::cout.
giblit wrote:
If it was iostream there would be no need for cin since it would be input and output.
http://ideone.com/t9BGIS if only it worked...
That didn't prove anything. You used cout(ostream) for output and cin(istream) for input with an iostream object.

What I was saying anyways is that you can't do this:
1
2
std::cout << "enter age: ";
std::cout >> age;
Last edited on
giblit wrote:
That didn't prove anything. You used cout(ostream) for output and cin(istream) for input with an iostream object.
I wasn't trying to prove anything. And no, I used the underlying stream buffers from cout and cin, I did not use cout and cin.
giblit wrote:

cout is an object of type iostream.

ostream

That was a typo on my part. I had stringstream on the brain.
Last edited on
Topic archived. No new replies allowed.