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".

1674 questions
413
votes
16 answers

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

What is the difference between printf() and cout in C++?
hero
  • 4,171
  • 3
  • 14
  • 6
374
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?
Jason Punyon
  • 37,168
  • 13
  • 93
  • 118
318
votes
27 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
  • 3,555
  • 4
  • 17
  • 17
275
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
  • 2,815
  • 3
  • 16
  • 6
242
votes
4 answers

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
  • 3,854
  • 5
  • 19
  • 32
219
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,213
  • 2
  • 10
  • 5
170
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,147
  • 6
  • 31
  • 48
161
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
145
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
  • 10,914
  • 19
  • 53
  • 94
107
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,305
  • 2
  • 10
  • 11
82
votes
8 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
  • 2,699
  • 9
  • 34
  • 58
75
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
65
votes
7 answers

C++ alignment when printing cout <<

Is there a way to align text when printing using std::cout? I'm using tabs, but when the words are too big they won't be aligned anymore. Sales Report for September 15, 2010 Artist Title Price Genre Disc Sale Tax Cash Merle Blue …
user69514
  • 24,321
  • 56
  • 146
  • 183
65
votes
11 answers

How to print Unicode character in C++?

I am trying to print a Russian "ф" (U+0444 CYRILLIC SMALL LETTER EF) character, which is given a code of decimal 1092. Using C++, how can I print out this character? I would have thought something along the lines of the following would work,…
James Raitsev
  • 82,013
  • 132
  • 311
  • 454
63
votes
5 answers

what does cout << "\n"[a==N]; do?

In the following example: cout<<"\n"[a==N]; I have no clue about what the [] option does in cout, but it does not print a newline when the value of a is equal to N.
Siva Prasad
  • 743
  • 5
  • 9
1
2 3
99 100