ostream Questions
10
Solved
I am learning C++. cout is an instance of std::ostream class.
How can I print a formatted string with it?
I can still use printf, but I want to learn a proper C++ method which can take advantage ...
Windbroken asked 27/2, 2013 at 7:7
9
Solved
I want to write a function that outputs something to a ostream that's passed in, and return the stream, like this:
std::ostream& MyPrint(int val, std::ostream* out) {
*out << val;
retu...
Leishaleishmania asked 6/7, 2009 at 16:28
6
Solved
I've been googling around and I just can't find a simple answer to this. And it should be simple, as the STL generally is.
I want to define MyOStream which inherits publicly from std::ostream. Let...
Woad asked 21/4, 2009 at 12:37
9
Solved
double x = 1500;
for(int k = 0; k<10 ; k++){
double t = 0;
for(int i=0; i<12; i++){
t += x * 0.0675;
x += x * 0.0675;
}
cout<<"Bas ana: "<<x<<"\tSon fai...
Breaker asked 6/3, 2011 at 17:13
3
Solved
I had an error while editing a C++ file and Xcode put out a suggestion I clicked fix and I've been getting this pop up every time I try to run ANY file or project. More than that that I can't unins...
4
Solved
I have difficulties in understanding the sequence of calls in the code below.
I was expecting to see the output below
A1B2
While I can see that the output I get is
BA12
I thought that the c...
Flight asked 11/2, 2013 at 10:11
5
Solved
I was reading the cplusplus.com tutorial on I/O. At the end, it says fstream buffers are synchronized with the file on disc
Explicitly, with manipulators: When certain manipulators are used on
str...
1
Solved
Question
Consider the following struct:
template<typename T>
struct stream
{
using type = decltype(
std::declval<std::ostream>() << std::declval<T>()
);
};
template<...
1
Solved
I've been implementing a codecvt for handling indentiation of output streams. It can be used like this and works fine:
std::cout << indenter::push << "im indentet" << in...
6
Solved
I am refactoring some legacy code which is using printf with longs strings (without any actual formatting) to print out plain text table headers which looks notionally like this:
| Table | Column ...
Syringomyelia asked 13/2, 2013 at 19:2
5
Solved
In python, the following instruction: print 'a'*5 would output aaaaa. How would one write something similar in C++ in conjunction with std::ostreams in order to avoid a for construct?
6
Solved
I am writing a small matrix library in C++ for matrix operations. However, my compiler complains, where before it did not. This code was left on a shelf for six months and in between I upgrad...
Stank asked 24/1, 2009 at 16:34
2
Solved
The cppreference page on std::setbase says:
Values of base other than 8, 10, or 16 reset basefield to zero, which corresponds to decimal output and prefix-dependent input.
How come?
Is there...
4
I want to control whether my ostream outputting of chars and unsigned char's via << writes them as characters or integers. I can't find such an option in the standard library. For now I have ...
Microphysics asked 8/6, 2012 at 14:5
5
Solved
Consider this code snippet:
#include <iostream>
#include <string>
#include <limits>
int main()
{
std::cout << std::numeric_limits<double>::quiet_NaN();
}
When com...
5
Solved
At 50:40 of http://channel9.msdn.com/Events/GoingNative/2013/Writing-Quick-Code-in-Cpp-Quickly Andrei Alexandrescu makes a joke about how not efficient/slow istream is.
I had an issue in the...
Crockery asked 8/9, 2013 at 21:21
17
Solved
I want to work with unsigned 8-bit variables in C++. Either unsigned char or uint8_t do the trick as far as the arithmetic is concerned (which is expected, since AFAIK uint8_t is just an alias for ...
Metaxylem asked 23/3, 2009 at 12:42
8
Solved
How do I do the following with std::cout?
double my_double = 42.0;
char str[12];
printf_s("%11.6lf", my_double); // Prints " 42.000000"
I am just about ready to give up and use sprintf_s.
More ...
Bari asked 16/8, 2012 at 14:28
5
Solved
well basically it should list all the vector coords in this kind of format :
(x, y, z)
but at the moment it does like this (x, y, z, )
easiest way would be using if in the for cycle, but can i s...
9
Solved
I'm looking for a std::ostream implementation that acts like /dev/null. It would just ignore anything that is streamed to it. Does such a thing exist in the standard libraries or Boost? Or do I hav...
3
Solved
I'd like to add a timestamp to certain outputs to the std::cout / std::cerr ostreams, without using modified standard streams, like so:
std::cerr << timestamp << "Warning!\n";
or so:...
Calices asked 23/1, 2020 at 17:11
2
This question follows a discussion in the comments here.
In Eric Niebler's ranges-v3 library (which is sort-of becoming part of the standard for C++20), ranges::ostream_iterator is default-constru...
3
Solved
I am trying to overload
<<
operator. For instance
cout << a << " " << b << " "; // I am not allowed to change this line
is given I have to print it in form...
Marquettamarquette asked 3/10, 2018 at 5:17
6
Solved
How to determine weather ostream is a file or a console stream. In the following program I want to print "Hello file!" while writing to a file and "Hello console!" while writing to console. What co...
3
Solved
I'd like an interface for writing to an automatically resizing array. One way to do this is with a generic std::ostream *.
Then consider if ostringstream is the target:
void WritePNG(ostream *out...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.