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
512
votes
16 answers

'printf' vs. 'cout' in C++

What is the difference between printf() and cout in C++?
hero
  • 5,161
  • 3
  • 16
  • 6
442
votes
16 answers

How do I print a double value with full precision using cout?

In my earlier question I was printing a double using cout that got rounded when I wasn't expecting it. How can I make cout print a double using full precision?
Restore the Data Dumps
  • 38,967
  • 12
  • 96
  • 122
408
votes
33 answers

How do I print out the contents of a vector?

How do I print out the contents of a std::vector to the screen? A solution that implements the following operator<< would be nice as well: template std::ostream &…
forthewinwin
  • 4,455
  • 4
  • 19
  • 17
325
votes
6 answers

Error "undefined reference to 'std::cout'"

Shall this be the example: #include using namespace std; int main() { cout << "Hola, moondo.\n"; } It throws the error: gcc -c main.cpp gcc -o edit main.o main.o: In function `main': main.cpp:(.text+0xa): undefined reference to…
D1X
  • 5,025
  • 5
  • 21
  • 36
315
votes
7 answers

How can I pad an int with leading zeros when using cout << operator?

I want cout to output an int with leading zeros, so the value 1 would be printed as 001 and the value 25 printed as 025. How can I do this?
jamieQ
  • 3,215
  • 3
  • 18
  • 6
259
votes
3 answers

cout is not a member of std

I'm practicing using mulitple files and header files etc. So I have this project which takes two numbers and then adds them. Pretty simple. Here are my files: main.cpp #include #include "add.h" int main() { int x = readNumber(); …
Paul Hannon
  • 2,613
  • 2
  • 13
  • 5
217
votes
8 answers

uint8_t can't be printed with cout

I wrote a simple program that sets a value to a variable and then prints it, but it is not working as expected. My program has only two lines of code: uint8_t a = 5; cout << "value is " << a << endl; The output of this program is value is , i.e.,…
CoderInNetwork
  • 2,923
  • 4
  • 22
  • 39
193
votes
10 answers

C++ cout hex values?

I want to do: int a = 255; cout << a; and have it show FF in the output, how would I do this?
user34537
190
votes
12 answers

How to print to console when using Qt

I'm using Qt4 and C++ for making some programs in computer graphics. I need to be able to print some variables in my console at run-time, not debugging, but cout doesn't seem to work even if I add the libraries. Is there a way to do this?
lesolorzanov
  • 3,536
  • 8
  • 35
  • 53
151
votes
7 answers

Why I cannot cout a string?

Why I cannot cout string like this: string text ; text = WordList[i].substr(0,20) ; cout << "String is : " << text << endl ; When I do this, I get the following error: Error 2 error C2679: binary '<<' : no operator found which takes a…
Ata
  • 12,126
  • 19
  • 63
  • 97
130
votes
7 answers

What is the difference between cout, cerr, clog of iostream header in c++? When to use which one?

I tried researching the difference between cout, cerr and clog on the internet but couldn't find a perfect answer. I still am not clear on when to use which. Can anyone explain to me, through simple programs and illustrate a perfect situation on…
Arlene Batada
  • 1,565
  • 2
  • 11
  • 11
105
votes
9 answers

How to make C++ cout not use scientific notation

double x = 1500; for(int k = 0; k<10 ; k++){ double t = 0; for(int i=0; i<12; i++){ t += x * 0.0675; x += x * 0.0675; } cout<<"Bas ana: "<
Yunus Eren Güzel
  • 3,018
  • 11
  • 36
  • 63
97
votes
2 answers

C++ printing boolean, what is displayed?

I print a bool to an output stream like this: #include int main() { std::cout << false << std::endl; } Does the standard require a specific result on the stream (e.g. 0 for false)?
user788171
  • 16,753
  • 40
  • 98
  • 125
87
votes
2 answers

'cout' was not declared in this scope

I have a C++ program: test.cpp #include int main() { char t = 'f'; char *t1; char **t2; cout<
user494461
85
votes
17 answers

how do I print an unsigned char as hex in c++ using ostream?

I want to work with unsigned 8-bit variables in C++. Either unsigned char or uint8_t do the trick as far as the arithmetic is concerned (which is expected, since AFAIK uint8_t is just an alias for unsigned char, or so the debugger presents it. The…
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
1
2 3
99 100