2,557 questions
-5 votes
1 answer
145 views
Why is auto becoming an int type in the following code: [duplicate]
How is the sum of three doubles not a double?! int main() { auto answer = 1.0 + 2.0 + 3.0; std::cout << answer; return 0; } output: 6 What?!
16 votes
2 answers
717 views
Parsing of small floats with std::istream
I have a program that reads the coordinates of some points from a text file using std::istringstream, and then it verifies the correctness of parsing by calling stream's operator bool(). In general it ...
5 votes
2 answers
220 views
How to stop a thread blocked on std::getline()? [duplicate]
In my application, I have a thread which just runs std::getline() constantly to get user input, to then send it to a server via a socket. I've made a signal handler to close the program properly when ...
0 votes
0 answers
103 views
Adding stream function to an io class
I have been thinking about this for some time now, I know what I want but I am not sure how to approach the solution. I have the following interface class class connection { protected: ... ...
1 vote
1 answer
79 views
Why getline is not inputting when previous cin is integer overflow
When the t variable is within int bounds, getline input behavior is fine. but when the value given to t is out of int bounds, getline behavior is weird why so ? cin>>t; string s(10, '&'); ...
-1 votes
1 answer
233 views
Undefined reference to std::cout? [duplicate]
I started with the easiest piece of code #include <iostream> using namespace std; int main() { cout << "Hello World!"; return 0; } I setup VScode to run C++ and this is ...
-4 votes
1 answer
140 views
How to change back to showing numbers based on significant digits after applying the "fixed" parameter to setprecision()
The setprecision() function can display numbers based on significant digits or number of decimals. But I have found a problem using this. In particular, when I start using the "fixed" ...
0 votes
1 answer
79 views
Contents of IO buffer unknown == unsafe?
My focus here shall be the following quote taken from the manual description of setvbuf, which startled me: If buffer is not a null pointer, instructs the stream to use the user-provided buffer of ...
2 votes
3 answers
149 views
How could I implement an assert function that support iostream
I would like to implement a CHECK() function that can work like this: int a = 1; int b = 2; int c = 1; CHECK(a == b) << "check failed" << endl; // this will abort the program ...
1 vote
0 answers
43 views
Unexpected behavior from c++ std::cin.get() [duplicate]
Using a book as a tutorial on C++ streams, I typed out the following code: //include std IO header #include <iostream> //start here int main() { int TypedLetter; std::cout << &...
-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 ...
2 votes
1 answer
183 views
Why are log lines missing without a flush?
I have a simple class in C++20 that logs data to a file line by line for Windows platform. To ensure thread safety, I use a static std::mutex to serialize the write operations. However, I encounter an ...
1 vote
1 answer
138 views
How to read data from a binary file to a vector in c++?
I want to read a binary file into a vector. Everything seems to work fine, since all the values have the correct values. Except the binary values/data isn't inputted into data or rather data isn`t ...
4 votes
2 answers
2k views
iostream not found with g++ and clang on macos
I'm trying to compile StegHide from source and I got an error message, saying that iostream can't be found. I wrote the following program and compiled it with -std set to all standards that my system ...
0 votes
0 answers
245 views
Msys2/MinGW-w64: Can't locate iostream - error: "cannot open source file iostream"
I'm new to coding, and our teacher advised us to use Visual Studio Code as our text editor, and also to follow YouTube tutorials on how to install Msys2 and the MinGW-w64 toolchain to use as a ...