1,881 questions
-3 votes
0 answers
150 views
Why excatly are std::cin/std::cout slower than scanf/printf? [duplicate]
I understand that std::cin/std::cout are generally slower than scanf/printf, and that's primarily due to synchronization with C’s standard streams. However, all explanations I saw just say that and ...
2 votes
2 answers
155 views
How to flush cin including all occurrences of newline
My app first takes some input, then it 'thinks' showing a progress bar, then throws an exit code and waits with getchar() for ENTER to be clicked before exiting. The problem is that if I click ENTER ...
1 vote
2 answers
108 views
cin type check failed for '+'/'-'
The scenario is: input integers and characters alternatively and read them into variables of the right type. I took the straightforward approach: read anyways as if they were all integers; when failed,...
0 votes
0 answers
41 views
Error in max() while trying to use std::cin.ignore in C++ [duplicate]
I created a function that would take the input from the user. This is the function: int InputHandler::takeInput() { int userInput; while (true) { std::cout << " Enter 0 ...
-1 votes
1 answer
64 views
QT creator 15.0 run in terminal for proper cout and cin functionality
I want to make cin>> work in QT, so it's needed to use the external terminal, not the application output. I followed all the instructions given in the previous answers about cin>> not ...
0 votes
0 answers
45 views
cin.peek() is blocked after running stty raw
Let's limit the topic to determine whether an ESC or Up key is stroked by stardard c++. After runing stty raw in console and then combining getchar() and cin.peek() in c++, it should be ok to finish ...
0 votes
2 answers
77 views
Manipulating 2d arrays in C++ and having trouble iterating through all of the data to create new arrays / go through the loops for the operation
I am writing a program for C++ that takes the user input with the first line containing the n integer ranging from 1-9 that informs on the grid size for the following data. then the grid with n number ...
0 votes
0 answers
30 views
C++ setvbuf and sync_with_stdio(false); [duplicate]
I use CLion and if I don't have the line setvbuf(stdout, nullptr, _IONBF, 0); I don't get output in the console when debugging. But I also use: std::ios_base::sync_with_stdio(false); std::cin.tie(...
0 votes
0 answers
68 views
What is the correct order of input, and how does it work precisely?
When I want to understand how to input data from the keyboard into a variable, I start by asking how cin and >> work in this context. What is the difference between them, and how are things ...
1 vote
1 answer
89 views
Declaration of dynamic array before getting array length [duplicate]
In dynamic allocation of arrays at runtime, when the array is declared before getting the array length, I encountered a behavior that could not explain. In the following code, the user provides the ...
0 votes
0 answers
77 views
Is it possible to pass std::cin to a function wanting an iostream?
I am using a library that has a function taking an iostream for a data stream, but I want to pass std::cin. It apparently is not possible to pass an istream to an iostream, but is there way around ...
0 votes
0 answers
29 views
Cin causes the value of a variable to change unexpectedly [duplicate]
So I am following this book Programming: Principles and Practice Using C++ 3rd edition and in section 2.3 Author gives the following code: cout << "Please enter your first name and age\n&...
2 votes
0 answers
98 views
Ensuring std::cin doesn't allow non-integer input
The problem arises from the std::cin's weird behavior of treating std::uint8_t and std::int8_t as char-like types so it allows the input to be a character instead of a number and std::cin doesn't fail ...
1 vote
1 answer
98 views
Does the empty() function in C++ work with cin?
I'm validating string input in C++, to make sure that the input is not empty. I know how to do it using the empty() function with getline(), but I want to know why it's not working when I use cin. ...
0 votes
0 answers
64 views
cin command being entirely ignored
I'm very new to programming of any kind, so to practice, I'm trying to make a simple game where you select a dice (d4, d6, d8, etc.). Then a random number generator rolls that dice, and you have to ...