776 questions
53 votes
2 answers
3k views
Why is 0.0 printed as 0.00001 when rounding upward?
If in a C++ program, I activate upward rounding mode for floating-point numbers and print some double-precision value already rounded to an integer, e.g.: #include <cfenv> #include <iostream&...
0 votes
1 answer
122 views
error: no match for 'operator<<' (operand types are 'std::basic_ostream<char>' and 'const cs10b_fraction::Fraction')
I get this error even though I overloaded the << operator. My prototype is as follows, placed within the Fraction class header file. friend std::ostream& operator << (std::ostream&,...
1 vote
2 answers
113 views
Verbosity Filter for std::ostream [closed]
This is the brute-force inelegant mechanism that illustrates what I could do (likely done with MACROS in the end): void myFunction(std::ostream& _log) { int threshold = 100; ... if (...
-1 votes
2 answers
112 views
Accept binary data via ostream interface and buffer into vector<uint_8>
Motivation for this question: the C++ API to Google's Protobuf serializes its messages into ostream: bool SerializeToOstream(ostream* output) const;: writes the message to the given C++ ostream. ...
2 votes
1 answer
67 views
How to get state of ostream when wrapped inside osyncstream
Is there a way to extract iostate (goodbit,badbit, failbit) or other means of error state of a std::ostream when I access this std::ostream through a std::osyncstream. I would like to detect whether ...
-2 votes
2 answers
93 views
no match for operator<<(std::ostream, ns::Type) when in the global namespace
Can someone explain why the << operator cannot be found when it's in the global namespace? Also, why might it be a problem if it could be? #include <ostream> #include <iostream> ...
1 vote
1 answer
120 views
How do I output to a file via Ranges from C++
I have a simplified analogue of netgen in C++. In one pipeline, I need to output to a file the coordinates of those nodes (as a container std::array of three elements) that fall inside a sphere of a ...
0 votes
1 answer
108 views
Assign reference parameter for ostream to reference member variable [duplicate]
I'm having trouble passing a reference to std::ostream to a class constructor and assigning it to a reference member variable. I have two files: // ./include/HelloWorld.hpp #ifndef __HELLOWORLD_H__ #...
0 votes
1 answer
100 views
How to implement multiple insertion operators (<<) for a C++ class?
I output my class objects using cout or ofstream. I understood that the insertion operator << is the standard way to convert an object to a string or print it. I would like to use different ...
0 votes
1 answer
172 views
C++ problem with std::ostream operator<< in template class [duplicate]
I wouldn't have this problem if I put the class code in the same header or same .cpp file, but when I have the class specification in the header and the class code in a separate .cpp file, I get this ...
-1 votes
2 answers
67 views
Support std::hex in custom operator<<
I have written my own operator<< implementation in my Logger class: #pragma once #include <map> #include <vector> #include <string> class Logger { public: enum Severity ...
0 votes
0 answers
23 views
"no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'Diem2D')"
enter image description here i tried to used operator istream and ostream but it doesn't work. I'm writing a HinhTron class from the existing Diem2D class to use point coordinates from the 2D class. ...
3 votes
0 answers
136 views
Overloading the shift operator << in C++ [closed]
As a university assignment I have to implement the ostream class of C++ standard library. I have header files with the function declarations and .cpp files, where I have to implement the functions ...
0 votes
4 answers
213 views
How would I make two ways to output something with <<?
For example, if I wanted to have a default version of outputting with << and a detailed version. myClass myObject(//Constructor parameters); cout << myObject << "\n"; cout ...
-2 votes
3 answers
125 views
The problem is writing operator overloading << and >> using templates
I have a class of shapes, it works on the principle that a shape consists of points (x and y coordinates). But overloading the input and output operators I encountered a problem that could serve as an ...