Questions tagged [cout]

std::cout is the global stream object provided by the C++ standard library for writing to the standard output stream.

For more general questions about std::ostream use the or tags.

Bjarne Stroustrup, the creator of C++, explains that cout is pronounced "see-out" and the "c" stands for "character". (wcout is used for wide character output to the standard output stream)

1820 questions
22
votes
2 answers

std::cout equivalent at compile time, or static_assert stringification of compile-time constant values in c++11

Is there a way to print the value of a constexpr or #defined value at compile time? I want the equivalent of std::cout <<, or some way to do something like constexpr int PI_INT = 4; static_assert(PI_INT == 3, const_str_join("PI_INT…
Jason Gross
  • 5,928
  • 1
  • 26
  • 53
21
votes
5 answers

This very simple C++ program using the standard library doesn't compile with GCC

I can't figure out why this isn't working... I am working in Linux. g++ doesn't do anything. gcc prints the following: /tmp/ccyg7NDd.o: In function `main': test.cc:(.text+0x14): undefined reference to `std::cout' test.cc:(.text+0x19): undefined…
spatara
  • 893
  • 4
  • 15
  • 28
21
votes
3 answers

Hide user input on password prompt

Possible Duplicate: Read a password from std::cin I don't work normally with the console, so my question is maybe very easy to answer or impossible to do . Is it possible to "decouple" cin and cout, so that what I type into the console doesn't…
dom0
  • 7,356
  • 3
  • 28
  • 50
21
votes
10 answers

Multiplying a string by an int in C++

What do I have to do so that when I string s = "."; If I do cout << s * 2; Will it be the same as cout << ".."; ?
skittles sour
  • 479
  • 1
  • 4
  • 7
20
votes
1 answer

Unbuffered output with cout

How can you get unbuffered output from cout, so that it instantly writes to the console without the need to flush (similar to cerr)? I thought it could be done through rdbuf()->pubsetbuf, but this doesn't seem to work. The following code snippet…
Charles Salvia
  • 52,325
  • 13
  • 128
  • 140
19
votes
6 answers

How do I use for_each to output to cout?

Is there a more straight-forward way to do this? for_each(v_Numbers.begin(), v_Numbers.end(), bind1st(operator<<, cout)); Without an explicit for loop, if possible. EDIT: How to do this for std::cin with a std::vector if possible? (How to read n…
nakiya
  • 14,063
  • 21
  • 79
  • 118
19
votes
3 answers

Called a function with "cout" statement inside a "cout" statement

I came across this rather vague behavior when messing around with code , here's the example : #include using namespace std; int print(void); int main(void) { cout << "The Lucky " << print() << endl; //This line return…
caramel1995
  • 2,968
  • 10
  • 44
  • 57
18
votes
2 answers

How to make cout behave as in binary mode?

Every time I do 'cout << endl' or even 'cout << "\n"' and then launch my program under Windows to output to a file ("a.exe < test.in > result.out") I get "\r\n" line endings in "result.out". Is there on earth a way to stop it doing so and just…
lithuak
  • 6,028
  • 9
  • 42
  • 54
17
votes
2 answers

cout - what it stands for?

Possible Duplicate: What does the “c” mean in cout, cin, cerr and clog? Can someone please explain to me what cout stands for?
smallB
  • 16,662
  • 33
  • 107
  • 151
17
votes
7 answers

printf vs. std::cout

Possible Duplicate: Should I use printf in my C++ code? If I just want to print a string on screen, I can do that using those two ways: printf("abc"); std::cout << "abc" << std::endl; The case is, and in the examples shown above, is there an…
aali
17
votes
3 answers

Printing zero-padded hex with std::cout

Say I have a dword I want to output in hex with std::cout and left-pad with zeros, so 0xabcd will be shown as 0x0000abcd. It seems like you would have to do this: uint32_t my_int = 0xabcd; std::cout << "0x" << std::hex << std::setw(8) <<…
jcai
  • 3,448
  • 3
  • 21
  • 36
16
votes
3 answers

Cout not printing number

Issue I'm getting no output from a simple cout, whereas a printf will always print the number: std::cout << variableuint8; // prints nothing printf("%u", variableuint8); // prints the number I've never run into this behavior before, and while I…
Adam Davis
  • 91,931
  • 60
  • 264
  • 330
16
votes
5 answers

What can explain std::cout not to display anything?

For whatever reason, std::cout does not display anything with my application. The description of my development environment follows. I am working on a Qt application using Qt Creator. Since Qt Creator can't be launched from my station (XP64), i am…
Benoît
  • 16,798
  • 8
  • 46
  • 66
16
votes
2 answers

Error: 'cout' : undeclared identifier; though I've included iostream header file in program

I am trying to compile the simple program below. But, it's not compiling & gives error: error C2065: 'cout' : undeclared identifier I want to ask you that why this program doesn't work though I've included iostream header file in it? #include…
yuvi
  • 1,032
  • 1
  • 12
  • 22
16
votes
2 answers

How to print a type vector> to screen c++?

I have a method that returns a value vector> and I cannot figure out how to print the contents of this vector. I was trying to loop through the contents but I get compiler errors. Here is an example of what I have tried. vector>…
user977154
  • 1,045
  • 4
  • 19
  • 39