Questions tagged [iostream]

The C++ iostream library is an object-oriented library that provides input and output functionality using streams. The iostreams classes support type-safe I/O of built-in types and can be extended to support user-defined types by overloading the >> and << operators.

Use this tag for questions about using iostreams, including writing overloaded operators for your own types.

The C++ standard library defines the std::istream, std::ostream and std::iostream base classes, as well as the standard stream objects std::cin, std::cout and std::cerr and derived iostream types for reading/writing files and strings. An iostream object is responsible for formatting operations (such as converting an integer 1234 into the string "1234" or vice versa) but uses a stream buffer (an object derived from std::streambuf) to interface with the underlying data stream. The stream buffer does any buffering of characters, manages the stream position and transports characters to/from an external device such as a file.

Iostreams use locales to support internationalization and are implemented as a hierarchy of class templates to support different types of characters, so that std::istream is actually a typedef for the specialization std::basic_istream<char, std::char_traits<char>>. The first template parameter is the character type used by the stream and the second is a traits class that provides operations for working with the character type.

A quick introduction to iostreams can be found in Chapter 3: A tour of the Standard Library in Stroustrup's TC++PL. Josuttis's The C++ Standard Library gives more information. The most detailed reference on using and extending iostreams is Langer & Kreft's Standard C++ IOStreams and Locales (see excerpt about stream buffers.)

2485 questions
1
vote
2 answers

Why is this FTP Download not outputting the downloaded data to my output file?

I'm working on writing my own FTPDownload class and an encountering an issue after having changed some things around that I'm trying to address. The code I'll paste below effectively starts a download and runs through it for some time, pulling full…
DigitalJedi805
  • 1,486
  • 4
  • 16
  • 41
1
vote
0 answers

Boost Iostreams, chaining gzip filter with home-made one

I meeting a execution issue while using the gzip filter of the Boost Iostreams library, combined with a buffered home-made one. I would like to know what is wrong in my way to do it. Firstly, my filter is a general DualFilter. It uses an buffer (of…
Ice
  • 31
  • 4
1
vote
1 answer

Operator overloading << error

I get the compiler error no match for 'operator<<' in 'std::cout << VertexPriority(2, 4u)' In the main class referred to this operator overloading, but I can't undestand where the error is. Here there is the operator overloading line, I…
giacomotb
  • 607
  • 4
  • 10
  • 24
1
vote
2 answers

How to use pass ifstream input in a function and output? C++

For example: ifstream input; input.open("file.txt"); translateStream(input, cout); input.close(); How to write function translateStream? void translateStream(XXXX input, YYYY output)? What are the types for input and output? Thanks
adam
  • 489
  • 1
  • 4
  • 5
1
vote
1 answer

stdout order with multiple threads

Suppose I have code like such: main() { start thread; put data in task queue; do some stuff wait for data in result queue; printf ("main got result\n"); fflush(stdout); } thread() { while (!done) { wait for data…
pavon
  • 16,574
  • 1
  • 23
  • 25
1
vote
1 answer

Redirect and timestamp std::cout

I need to redirect an ofstream to a file and timestamp every line that's printed. (It's part of a logging system). I have a working class that manages to do just that but it refuses to flush the file when std::endl is emmited. I'd apreciate any help…
user1783395
  • 95
  • 1
  • 5
1
vote
1 answer

Streamtokenizer to read very large numbers?

I have to take an input containing large numbers of order 10^9 in Java. How do I handle Inputs fast? Also since streamtokenizer.nval gives a double, how can I read larger values??
1
vote
3 answers

C++ Separate Function File

i'm trying to write my c++ program in different files, but I can't seem to get it to work. can someone help me? separate.cpp #include "separate.h" #include void Separate() { cout << "text"; } separate.h #include using…
NewFile
  • 501
  • 5
  • 10
  • 16
1
vote
1 answer

Why does std::codecvt not work as defined?

#include using namespace std; void f1() { wcout.imbue(locale("chs")); wcout << L"您" << endl; } void f2() { locale loc(wcout.getloc(), new codecvt()); wcout.imbue(loc); wcout << L"好" <<…
xmllmx
  • 39,765
  • 26
  • 162
  • 323
1
vote
1 answer

Why does inserting a std::basic_streambuf* to an ostream insert the buffer content?

Take this simple example program: // main.cpp #include #include int main(int argc, const char *argv[]) { using namespace std; fstream infile("main.cpp"); basic_streambuf *buf = infile.rdbuf(); cout <<…
1
vote
3 answers

Entering in an infinite loop while reading a file

This code accepts student name, father's name, roll no and age from input file and put it in a presentable manner in output file. In this code, when contents of input file are: Vicky Mohan 20094567 22 Ricky Rahul 20091234 21 It works fine. But if…
user2655324
1
vote
1 answer

custom std::hex manipulator that works for unsigned char

Please consider the following: unsigned char a(65); unsigned char z(90); std::cout << std::hex << a << ", " << z <
Benedict
  • 2,771
  • 20
  • 21
1
vote
3 answers

How do I compare two different strings from two separate text files?

I am a c++ rookie and do not know what I am doing wrong. My assignment is to compare two different .txt files, each containing an item along with either the number of items and the price of that item. I am then trying to print the names and prices…
John
  • 13
  • 1
  • 3
1
vote
3 answers

Dev C++ couldn't support with iostream.h header file in C++

Why the "Dev C++" couldn't support with iostream.h header file in C++..? How can I include iostream.h header file in Dev C++?
CAPRICORNER
  • 13
  • 1
  • 1
  • 3
1
vote
1 answer

Iterating Streams in Reverse

I would like to use std::find_if to traverse the contents of an std::streambuf in reverse. This involves constructing an std::reverse_iterator from an std::istream_iterator or std::istreambuf_iterator. Unfortunately, trying to do this, as shown in…
void-pointer
  • 14,247
  • 11
  • 43
  • 61