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

Operator overloading seems to work both ways for cout?

I've been tinkering around with classes and operator overloading in C++ - and recently I came across a code in which both cout << class_object and class_object << cout works if I overload the '<<' operator (to return individual class members).My…
Caife
  • 415
  • 1
  • 5
  • 16
0
votes
1 answer

C++: How do I print to ostream on both a file and the console within the same method where a file is being passed as an ostream object

void method(std::ostream &output){ cout << "some text"; } int main(){ method(std::cout); } This gets added to my file when I run my program like this ./program arg > file.txt How can I run this program so that this prints out to…
user1809913
  • 1,785
  • 1
  • 14
  • 25
0
votes
1 answer

How does cout know how to format different types?

This has been puzzling me for a while: with printf, you provide formmatters to dictate how a parameter should be interpreted, but cout doesn't require this. How does cout know to read a variable according to the correct type?
0
votes
1 answer

how to cout "count_if"-STL-function of a string?

I want to create a function/functor which counts the occurences of an letter in an vector of strings. For example: Output: Strings: one two three four five Letter: e Frequencies: 1 0 2 0 1 I think my algorithm would work (i have to solve it by…
0
votes
1 answer

C++ getline gives back some strange results

I'm trying to run this code: string p = "Test.txt"; ifstream fid(p.c_str()); while(!fid.eof()) { getline(fid,p); cout << "|s|" << p << "|e|" << endl; } But the result put's somehow of since it is like this: |e|line1 |e|line2 …
magu_
  • 4,766
  • 3
  • 45
  • 79
0
votes
0 answers

cout Not Working Reliably

I was working on a school project to make a blackjack/21 console application. The program is somewhat long and complicated, so will only put the offending code here. Complete code will be below. cout << "Before comp instruct"; cout << endl <<…
alexwho314
  • 29
  • 2
  • 9
0
votes
1 answer

Cannot deal with the text files' names and lengths which are stored in a structure

I wrote a code to get the text file names in a directory, get the length of the articles which are number of words in article, and the two steps seem to work well, and the outputs are what I wanted. Here I used linked list to store all the file…
OSrookie
  • 13
  • 3
0
votes
2 answers

Weird bug with floats in if-statement

So in my C++ code I have the following line of code for debugging purposes: if(float1 != float2) { std::cout<
user1782677
  • 1,963
  • 5
  • 26
  • 48
0
votes
2 answers

Inputing a string to an int produces wrong output in c/c++

#include #include using namespace std; int main() { // Declare a variable to store an integer int InputNumber; cout << "Enter an integer: "; // store integer given user input cin >> InputNumber; // The same with…
K_TGTK
  • 765
  • 1
  • 8
  • 24
0
votes
2 answers

How to do parsing istringstream C++?

I need to print some data from stream - istringstream ( in main () ). example: void Add ( istream & is ) { string name; string surname; int data; while ( //something ) { // Here I need parse stream cout <<…
user1779502
  • 573
  • 2
  • 8
  • 16
0
votes
2 answers

C++ : extern variable inside namespace and printf vs cout

i have a little problem with printf and i don't know why ! =>kernel.h #ifndef KERNEL_H #define KERNEL_H namespace kernel { extern const double h; } #endif // KERNEL_H =>kernel.cpp #include namespace kernel { const double…
awat
  • 175
  • 1
  • 1
  • 9
0
votes
2 answers

order of execution in do/while loop

I took the following example literally from Walter Savitch Absolute C++ book. It works (as one would expect from a scholar such as Walter Savitch). However, I am puzzled why as I will explain after the code citation: cout << "Enter a line of input…
Svalbard
  • 182
  • 2
  • 13
0
votes
1 answer

Output Multidimensional Vector of Objects

So, I am trying to simply print the content of the vector that I am creating. Essentially I am trying to output the player which would be an int (i.e. 1-4) and the player's hand which consists of Card objects. So, for example, I am trying to get it…
Barry Tormey
  • 2,966
  • 4
  • 35
  • 55
0
votes
3 answers

printing text-value of enum, not the value

I want to print the text value of an enum, if I enter 5, it will print F1. If i enter 63, it has to print H8. In the code below, I tried cout << "You chose: " << board_square(chosen_piece) << endl, but it prints the value twice. enum board_square { …
Lemonizer
  • 83
  • 2
  • 4
  • 14
0
votes
3 answers

C++ unexpected hangtime

I am trying to write a function in my program that loads a huge text-file of 216,555 words and put them as strings into a set. This works properly, but as expected, it will hang for a few micro seconds while looping through the file. But there is…
Sti
  • 8,275
  • 9
  • 62
  • 124
1 2 3
99
100