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

How to get input to a string that does not terminate with a space?

#include #include #include #include using namespace std; int main() { vectorGames; vector::iterator iter; string command; string name; cin>>command; if(command=="add"){ cout<<"You…
user3200451
  • 19
  • 1
  • 7
0
votes
3 answers

how printing exception by a class function that contains the string to print?

I have this: catch (Except& e) { std::cout << e.print() << std::endl; } I want this to print: OK you won! so I have the class: class Except{ public: std::string print() { std::string error("OK you won!\n"); return error; } }; I have…
user3036061
  • 87
  • 2
  • 9
0
votes
2 answers

Accessing objects from a linked list (custom implementation)

When using a linked list that stores numerous objects how would you go about access the data inside said object?. Example code. using namespace std; typedef struct node { …
Tony
  • 19
  • 1
  • 1
  • 6
0
votes
3 answers

ofstream - Can I redirect a "cout" into file?

I just wanted to know if there was some way yo be able to do this : ofstream exemple (name); exemple << Display(); Display() being a void method, that only do something like that : cout << "Something" << endl; I would do that because I have…
Marco Montalto
  • 215
  • 5
  • 15
0
votes
2 answers

C++ cout errors whenever it tries to print a function variable

I can use cout to print a normal variable just fine, but whenever I try to print a function variable(in this case, string input) the compiler shoots out the error: C2679: binary '<<' : no operator found which takes a right-hand operand of type…
Drew
  • 670
  • 8
  • 26
0
votes
4 answers

Difference between `cout << x` and `cout.operator<<(x)` and `operator(std::cout, x)`?

This is related to the difference-between-cout-x-and-cout-operator-x question, but still a little different... #include int main(){ std::cout << "hello" << std::endl; std::cout.operator<<("hello2"); …
GnomeDePlume
  • 1,642
  • 2
  • 15
  • 31
0
votes
3 answers

Freaky output: why would this code give any meaningful output, let alone this?

I'm not sure how to even state my question, but here we go... So, I have this class for which operator[] has an empty body (not yet implemented). Still, when I call it from main(), it produces an output. What's more, the output is exactly what was…
0
votes
2 answers

c++: print a string with specified length

In C++, using printf-s I want to write a char array (etc char asd[50]) to console with a specified 50 space (similar like "%.2d" method at decimals, if the string shorter fill it with spaces....) Tried %50s and %.50s methods, both of them wronged…
user3063349
  • 96
  • 1
  • 10
0
votes
2 answers

Line up text output in C++

So i have a program that reads from a text file and outputs to another text file. Here is the file text (format included) that it reads: Duckey Donald 85 Goof Goofy 89 Brave Balto 93 Snow Smitn 93 Alice Wonderful 89 Samina Akthar 85 Simba Green…
nfoggia
  • 513
  • 1
  • 8
  • 28
0
votes
6 answers

strange behavior in cout c++

Intro: In cout I expect any values passed by the insertion operator << to be displayed on screen. Normally one would think that the following code would work without fault: int n = 0; cout << n; And it does, and yes, it is good practice to always…
Andrew
  • 3,393
  • 4
  • 25
  • 43
0
votes
1 answer

Why does this print twice?

I can't figure out why the output is going through twice. int lines = 3 myReadFile.open("graph.txt"); if (myReadFile.is_open()) { //Read in each value one at a time while (!myReadFile.eof()) { for(int i = 0;…
DDukesterman
  • 1,391
  • 5
  • 24
  • 42
0
votes
4 answers

C++ Program calculate carpet cost of rooms

Currently I am in a C++ class and were are learning about functions. Our assignment was to create a program to calculate the total cost including price per sq foot, labor, and tax of each room given by the user's input for the count. Here is my…
byzzyby
  • 3
  • 1
  • 3
0
votes
3 answers

Is it possible to refresh two lines of text at once using something like a CR? (C++)

Right now, I have a console application I'm working on, which is supposed to display and update information to the console at a given interval. The problem I'm having is that with a carriage return, I can only update one line of text at a time. If I…
jakogut
  • 4,409
  • 6
  • 29
  • 41
0
votes
2 answers

Is it possible to cout without overwriting current text in the input?

Okay, so let's say I have a program that couts a line while the user may be typing in information. For this example, let's say we're using the code cout << "THIS CODE IS BEING COUTED" << endl; Let's say for our example, the user is in the process…
user2980207
  • 293
  • 1
  • 11
0
votes
3 answers

Why is cout not displaying x?

I am learning C++ and I created a simple void function that uses char. I prototyped the function up top, defined it in the int main and tried to output "Your name is " x. Can someone tell me why it only tells me "Your name is" and not the x (john)…
user1808010
  • 141
  • 1
  • 3
  • 11