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
0
votes
1 answer

c++ std::cout unespected output

Hi I'm writing some debug output with std::cout with this code: EDIT: as suggested I added a std::flush on each cout and an std::endl on each iteration int index = 0, size = vector.size(); for (iterate trough a vector) { std::cout <<…
Michele mpp Marostica
  • 2,445
  • 4
  • 29
  • 45
0
votes
2 answers

setw within a function to return an ostream

here is my function ostream margain(std::string firstWord) { ostream x; x << std::setw(20) << firstWord; return x; } in main I want to use the function as follow std::cout<< margain("start") << "````````````````````````````````````" <<…
aah134
  • 860
  • 12
  • 25
0
votes
1 answer

boost::asio blocks std::cout when reading from serial port

I'm using boost::asio to read from a serial port. I continuously read from the serial port and print it out through std::cout. But some strange things happens. I'm using TimeoutSerial class from here. My code goes like this: #include…
tom
  • 1,520
  • 1
  • 12
  • 26
0
votes
1 answer

Function working because of debugging line

I'm finding Harmonic numbers, the function cycles through until it finds the correct harmonic number as long as the line I was using to debug the program is input which was the cout line at the end. If I remove any portion of the cout, the program…
0
votes
1 answer

C++: cout statements making my program go haywire?

#include #include #include #include using namespace std; int playerHP = 20; int enemyHP = 20; int playerAtk =(rand()%4 + 5); //Find a random number between 5 and 8 int playerDef = (rand()%4…
Bob
  • 1,344
  • 3
  • 29
  • 63
0
votes
2 answers

Writing large amount of data to an ascii file fast in C++

I am writing a particle tracker in C++ which releases a particle in a numerical flow field and then integrates in time to calculate the new position of the particle. This is done for as many particles as time allows (hopefully millions) for…
EJG89
  • 1,189
  • 7
  • 17
0
votes
5 answers

My C++ Program isn't executing my cout code

I am learning C++, and I am trying to make a simple program which prints 5 variables, as my book said to do this, but it is not executing my code. #include using namespace std; int main() { //Program Code below return 0; char…
user2603709
  • 33
  • 1
  • 3
0
votes
1 answer

Reset properties of std::cout for integers or doubles in C++

At various places in my code, I set certain stream properties, such as in std::cout << fixed << 4.56342;, in order to manipulate how an integer or double appears when printed to standard out. Sometimes during a particular runtime flow, std::cout is…
synaptik
  • 8,971
  • 16
  • 71
  • 98
0
votes
2 answers

vector handling displaying output

Vector data: Mary Daryl Cherry Mary vector position[0] Daryl vector position[1] Cherry vector position[2] Vector size: 3 Vector name: data No need for Mary [ if vector[0], then display vector[1] and vector[2]) Scene 0: Daryl is on Scene_0 Cherry…
user1745860
  • 207
  • 1
  • 5
  • 11
0
votes
4 answers

Control display output using vector

Vector size: 2 Vector data: Carol Mary if(vector.size() >=2) { cout<
user1745860
  • 207
  • 1
  • 5
  • 11
0
votes
1 answer

Reverse order when using std::cout

The program below outputs 10. I expected it to first print 0 (the else branch of function f) and then to print 1. How come that the order is reversed? #include using namespace std; int f(bool& b){ if (b==true){ return…
Slazer
  • 4,750
  • 7
  • 33
  • 60
0
votes
1 answer

Printing to terminal with Multi-stage compiling and an infinite loop

Ok, I have 5 c++ files: PegRTU.cpp, PegIOHandler.cpp, PegIOHandler.h, pegio.c, pegio.h (PegRTU.cpp contains my main() method). I compile them with the following commands using gcc and g++: gcc -c pegio.c -o pegio.o g++ -c PegIOHandler.cpp -o…
Cornel Verster
  • 1,664
  • 3
  • 27
  • 55
0
votes
3 answers

need help debugging character input

I wrote a program that reads input a word at a time until a lone 'q' entered.The program then report the number of words that began with vowels,the number that began with consonants,and the number that fit neither of those categories. #include…
fish_shoes
  • 115
  • 9
0
votes
3 answers

Order of outputting with cout output stream

I am trying to run this simple code int a=0; cout<
Slazer
  • 4,750
  • 7
  • 33
  • 60
0
votes
4 answers

Don't understand why this std::cout is printing this

I got is c++ code below. #include using namespace std; int main() { char ch; int ct1, ct2; ct1 = ct2 = 0; while ((ch = cin.get()) != '$') { cout << ch; ct1++; if (ch = '$') ct2++; cout << ch; } cout << "ct1 = " <<…
fish_shoes
  • 115
  • 9
1 2 3
99
100