Questions tagged [cout]
std::cout is the global stream object provided by the C++ standard library for writing to the standard output stream.
1,786
questions
-1
votes
1
answer
37
views
Printing to the console while still getting input
I want to know if there is a way to, as the title says, console out on the lines next to the line that gets the input.
I want the console to look like this:
Using cin and then cout will only print ...
0
votes
1
answer
28
views
invalid operands to binary expression ('basic_ostream<char, std::char_traits<char> >' and 'vector<std::string>' (aka 'vector<basic_string<char> >'))
I am trying to do a program to check for all permutations of a word. Link to Codewars Kata: https://www.codewars.com/kata/5254ca2719453dcc0b00027d/train/cpp.
In order for me to continue I need to ...
0
votes
1
answer
39
views
Cout trigger breakpoint when i try to print something which is not a string
I trying to build fft function in c++.
I realized there are errors in the process so I wanted to print each step on it's own.
When I try to do cout to everything that is not a string it trigger a ...
-2
votes
1
answer
37
views
In C++, cout is not printing the output when a function is call from another file to main file [closed]
Here I have created three files named,
main.cpp (Main file)
#include"practicals.hpp"
using namespace std;
int main()
{
firstPractical;
return 0;
}
practicals.hpp (Custom header ...
0
votes
1
answer
39
views
cout is only working after gets() eventhough i had written it before gets()
I have just started learning c++.
I wrote this program for finding how many vowels in a sentence.
But when i run the program it asking for input before the cout and cout is working after gets()
#...
0
votes
1
answer
49
views
cout macro value doesn't work as expected [closed]
#include<iostream>
using namespace std;
#define C 1<<(8*1)
int main(){
if(C==256){
int a=C;
cout<<a;
}
}
My expectation is 256 but it print 18. What's wrong with it? ...
0
votes
0
answers
27
views
VS Code: Declaring a stack leads to problems with cout
I am learning C++ and was writing a simple program when I noticed that declaring a stack caused cout to not output to the terminal. Here is my program:
#include <iostream>
#include <...
0
votes
0
answers
41
views
Why does my code print some random numbers insted of "Hello World"? [duplicate]
#include <iostream>
int main()
{
std::cout << 'Hello World' << std::endl;
}
output:
1869769828
What should I do to my code to print Hello World?
0
votes
2
answers
43
views
getLine() does't seem to work after first input - C++
I'm currently new to C++ and learning the basic syntax.
I'm exploring how getLine() works and I'm trying to compare the standard input and a getline().
#include <iostream>
#include <string>...
0
votes
1
answer
18
views
How to increase the size of black square using unicode? C++
i am making chess and i used this code to insert white blocks
for(column=8;column>=1; column--)
{if ( column%2 == 0)
{
cout<<(char)254u<<&...
-4
votes
1
answer
45
views
Fast I/O question for competitive programming what does the arrow operator (->) do in this case? [duplicate]
What is the difference between
cin.tie(0);
ios:sync_with_stdio(0);
and
cin.tie(0) -> sync_with_stdio(0);
I do this so that both cin and cout become faster and I use the cin.tie(0) to reduce the ...
2
votes
1
answer
43
views
How to get non scientific output while still not outputing zeros in std::cout?
Here's is an example:
std::cout << 1000000.0 << "\n";
std::cout << std::fixed << 1000000.0 << "\n";
std::cout << std::fixed << std::...
0
votes
1
answer
67
views
Why `std::cout << std::this_thread::get_id()` does not compile? [duplicate]
Why std::cout does not compile in this code snippet,
#include<future>
#include<iostream>
#include<array>
#include<algorithm>
std::array<int, 100> arr;
int sum=0;
struct ...
0
votes
0
answers
74
views
What does cout<<' '<<f(x); display here?
#include <bits/stdc++.h>
using namespace std;
int f(int x)
{
int n;
if(x>0)
{
if(x%2==0)
{
cout<<x%10;
n=1+f(x/10);
}
...
1
vote
1
answer
16
views
why cout not works before getche() in VC++ 6.0?
I want to show a message before an input :
cout<<"Enter a char:";
ch = getche();
But when running program it does not show the message and getche() works and after that the message is ...
0
votes
2
answers
48
views
How do I return a string with variables and characters in c++?
I have a string function that I would like to output the following cout lines.
string print_ticket(void){
if(sold_status == true){
cout<<seat_number<<" "<&...
1
vote
0
answers
52
views
how to remove '+' in scientific mode output
I have this code:
std::cout << std::scientific << 1e9;
It outputs 1.000000e+09 but I don't want the +.
I tried using std::showpos , it doesn't work for that.
I thought about writing an ...
0
votes
2
answers
39
views
setw() and setfill() not working...what am i doing wrong?
what i am trying to do is print double datatype with precision 2,setw(15),fill spaces with _(underscore) and with prefix - or +.for example if number is 2006.008 output should be _______+2006.01
my ...
-3
votes
2
answers
68
views
I want to use cout more comfortably
I want to use cout to print out this sentence: "You can build piramid which floor is only odd. not even", but I want to do it more comfortably. Just like the way below. But, when I use this ...
1
vote
1
answer
182
views
Vector point std::vector<cv::Point>
I am trying to draw a trajectory on an image and saving these trajectory points as std::vector<cv::Point> trajectoryPoint and I would like to access the data inside.
This a short snippet from ...
1
vote
3
answers
49
views
Manipulating the standard output stream to print multiline strings horizontally
So I have three strings and these strings are supposed to occupy 3 lines. I thought this was a good way to represent my string:
std::string str1 = "███████\n███1███\n███████";
std::string ...
0
votes
3
answers
72
views
How do I check if the program cout is empty?
I am facing a problem where I have a void function which prints out AVL tree node values using inorder traversal. However, I also need to print out "EMPTY" if the void function does not have ...
0
votes
1
answer
87
views
cout printing garbage when string is concatenated with array value
Here is my very basic C++ code:
#include <iostream>
char values[] = {'y'};
int main() {
std::cout << "x" + values[0];
}
My expected output would just be xy, but instead I ...
0
votes
0
answers
56
views
Clarification about function calls in cout needed
i'm doing an online c++ learning course with quiz. The last output line of this snippet is to be determined (comments added by me). Correct answer: 10. My question: why 10 and not 11?
Calling a(b) ...
0
votes
0
answers
16
views
std::cin unexpected behaviour on large integer input [duplicate]
cin unexpected behaviour on large integer input
When a large integer is provided as input, std::cin causes unexpected behaviour in the program.
std::cin unexpected behaviour when there is an integer ...
1
vote
1
answer
104
views
How to drop the expressions after <<?
There is a very simple log "system":
#include <iostream>
#if true
# define LOG std::cout
#else
# define LOG
#endif
int main()
{
LOG << "hi" << std::endl;
...
0
votes
0
answers
30
views
How do you catch the output of a void function that takes ostream as a parameter into a stringstream?
Let's say we have:
void print(std::ostream &o) {
o << "Hello World!";
}
and:
int main() {
std::stringstream ss;
ss << print(std::cout); // does not work
std::...
0
votes
0
answers
36
views
why cout statement in Ubuntu not working as expected?
I tried to write this code in Ubuntu and run it from terminal
but the problem is the second "cout" statement prined before the first one.
for (int i = 5; i > 0; i--) {
cout << &...
1
vote
1
answer
109
views
How to place a space at the end of cout
I need to know why c++ doesn't see the space just at the end of cout function.
I'm using CLion and C++ 23 (language_standart)
int main()
{
string Item ;
double Price ;
int Quantity ;
...
0
votes
0
answers
39
views
Filesystem c++, geting no output. Avoiding static compiling? [duplicate]
I'm having problems getting any output from the std::filesystem functions in C++, even from the most simple functions like current_path. I'm compiling with mingw64, g++ on Windows, it comes with C++17 ...
0
votes
1
answer
58
views
would clog and cout in c++ behave differently in outputing the value?
I am expecting a similar behavior for Cout and Clog since both are buffered outputs. But when i am trying, it comes out different.
COUT:
int main()
{
cout<<"Hello World" ;
...
0
votes
4
answers
132
views
thread safe std::cout using mutex
I try to make some thread safe std::cout and the best solution for me will look like the following:
void print(std::ostream &out)
{
pthread_mutex_lock(&m_mutex);
std::cout << ...
1
vote
2
answers
38
views
Why does left justification not work in the first iteration of a loop?
#include <iostream>
int main(){
using namespace std;
string s1("Hello1");
string s2("Hello2");
for(int i = 0; i < 3; i++){
...
0
votes
0
answers
44
views
(C++) I am trying to output the contents in a double array but it's not printing any decimal places when I need them to have a .00 on the end
[This is my first semester learning C++ so bear with me :) please]
I was able to write the program to work as intended, but without the decimal places that my professor wants in step 3 (seen below)
...
1
vote
2
answers
267
views
How to print debug message in the OpenBMC
I want to print debug message in the bmcweb of OpenBMC. The development language of OpenBMC is c++, and I print the message through printf and cout, but it does't work. In the console of qemu, I can ...
-1
votes
1
answer
72
views
I can't print out sentence with 'cout' in c++
first I not a native English speaker so if you find errors in my English ignore them,
below my code
#include <iostream>
#include <string>
#include <vector>
using namespace std;
//...
0
votes
0
answers
42
views
Is the output stream automatically flushed at the end of the program?
In C++, is the output stream automatically flushed when the program ends? (At the end of the main function).
-3
votes
3
answers
108
views
C++, Nothing in the output
I am new to C++ and coded my first main.cpp but I got an error, not exactly an error, it is a logical error, I guess because I wrote the following code:
#include <iostream> // including the ...
0
votes
1
answer
70
views
Why is this code not producing expected output?
#include<iostream>
using namespace std;
#define sp ' '
std::ostream& nl(std::ostream os)
{
return os << '\n';
}
int main()
{
cout << 1 << sp << 2 << ...
0
votes
1
answer
26
views
Printing an element from an octree with cout alters the content?
I tried creating an octree in c++. Seems to work fairly well, but when I print the content of the tree it returns an access violation error. Running this in debug will print two different numbers, ...
1
vote
1
answer
405
views
STM32 C++ and Retargeting std::cout to UART
I'm having trouble trying to get std::cout working on an STM32 using the STM32CubeIDE (generally a standard install of the STM32CubeIDE out of the package).
I've reviewed many sources about ...
0
votes
1
answer
25
views
Overloading and LinkedList
I was trying to overload cout operator to print a class.
The class consists of an integer value and a pointer. So I was hoping to print an integer value and a memory address, but I got an error. I got ...
-4
votes
2
answers
111
views
Difference between string literal and string in cout statement?
What is the difference between the following ways of printing a string?
std::cout << "hello";
// and
std::cout << std::string("hello");
They both appear to do the ...
2
votes
3
answers
107
views
How to print the elements of an array of structures?
I am new to c++ , I was trying to print the fields of a structure using an array.
I know the compiler is not able to understand what is inside deck[1] in the line for(int x:deck[1]), since deck[1] is ...
0
votes
0
answers
61
views
about efficiency of std::cout in c++ and alternative ways to print message
I'm learning C++, and as a exercise i am implementing a crude ASCII renderer, and my render function looks something like this:
void render() {
for(int y = 0;y < height;y++) {
for(int x ...
0
votes
1
answer
71
views
Why does cout writing out nothing?
Im a begginer in c++ and i dont know why this code isnt running. Its writing out nothing... not even the "a"
#include <iostream>
#include <vector>
using namespace std;
int main()
...
0
votes
0
answers
55
views
cout a string from a vector of strings
Im just a bit stuck on why I cant cout a string from a vector of strings. "item" appears to be a valid string and can be output to screen, but input_names[i] doesnt seem to return anything. ...
0
votes
3
answers
428
views
std::cout print all digits of float value
I have this function:
template<typename T> // T can be float, double or long double
void printAllDigits(T value)
{
std::cout << std::fixed << std::setprecision(999) << ...
0
votes
0
answers
8
views
Prevent thread from printing threadinfo to console
Every Time I run this Code I got the following Console output:
Attached to Thread
Attached to Thread
Detached from Process
Detached from Process
The whole process lasts about 4 ms.
I think the main ...
1
vote
1
answer
81
views
Passing the standard output of function A as the argument of function B in C++
I'm starting C++ and I'd like to code a linker
I first did a tokenizer executable that takes as an input a file and print in the standard output the list of its tokens
%./tokenizer input_file
Token 1 :...