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
0 answers

boost::iostreams with tokenizer without unnecessary copying

I'm trying to create a string I can tokenise, from a file. What works is boost::iostreams::stream_buffer file("file.txt"); boost::char_separator sep(","); std::string…
Delta_Fore
  • 3,079
  • 4
  • 26
  • 46
1
vote
2 answers

Android app throws java.util.concurrent.RejectedExecutionException: pool=128/128, queue=10/10

My production android app throws this exception. When I analysed crittercism I noticed that many of my async tasks were not completing. They were hanging on ClientSession.java:361 responseMessage = (AMessageStrategy)…
Siddharth
  • 9,349
  • 16
  • 86
  • 148
1
vote
4 answers

String made from the first char of another string - why is it also printing the full original string?

Learning C++. I just want to grab the first character in a string, then make a new string based on such character, and then print it out: #include using namespace std; int main(int argc, const char * argv[]) { string name = "Jerry"; …
Saturn
  • 17,888
  • 49
  • 145
  • 271
1
vote
1 answer

Setting std::io_base flags for custom stream class

I have a custom class called Stream class Stream public: Stream& operator<<(int i) { stream_ << i; return *this;} template Stream& operator<<(const CustomClass& c) { stream_ << c.toString() /*…
abumusamq
  • 780
  • 1
  • 10
  • 29
1
vote
3 answers

namespace detection

I'm trying to write a log library which would use an external tool To make the library more natural to use, i would like to be able to detect the namespace in which cout is used. concretly the result should be used like this namespace A { void…
tiridactil
  • 389
  • 1
  • 11
1
vote
2 answers

ostream, copy function printing string address, instead of string contents

This prints the address for my string, but not its' contents, #include #include #include #include #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { …
masT
  • 804
  • 4
  • 14
  • 29
1
vote
1 answer

C# style enums in C++

I'm trying to write a log library which would use an external tool i'm looking for convenient way to add Key-strings to the output stream to help parsing by the external tool while having the least impact on the programmer using the library The goal…
tiridactil
  • 389
  • 1
  • 11
1
vote
1 answer

ifstream::tellg differs on MSVC2012 and gcc (mingw) when file has trailing newline

ANSWER Even though everything was compiled and run on windows, I completely forgot tellg behaves as an unformatted input function and cannot be used reliably in text mode which is why I see the discrepancy. See std::basic_istream::tellg for…
Jesse Good
  • 50,901
  • 14
  • 124
  • 166
1
vote
1 answer

Reading txt multiple times

I have a program which uses a text_file to store lots of numbers. When I have to load those numbers I have to load it with 2500 numbers a time. I have a while loop to load it again and again and again... Now, the problem occurs in the while loop I…
abcdef
  • 236
  • 1
  • 5
  • 17
1
vote
1 answer

Why can't I assign anything to an array anymore

I have this implementation of a linked list class (using char arrays for strange reason) list_node::list_node(const std::string & input, int start, int end) { std::cout << "1 arg constructor called" << std::endl; letters = new char[end - start +…
user929404
  • 2,153
  • 1
  • 22
  • 27
1
vote
1 answer

Can I init a iostream from a buffer without copying it?

I have a buffer unsigned char *buffer filled with size bytes. I wanna init a stream from it. I can do it as follow, which copys the buffer bytes: string s(bytes, bytes + size); stringstream ss(s); I wonder if I can init a stream without that copy?
smilingpoplar
  • 1,065
  • 1
  • 15
  • 26
1
vote
2 answers

xcode 4.6 iostream file not found error?

I am facing a problem regarding iostream file not found in header file.I just added a c++ file in my project a header file also included by default with some macro definition and including iostream file as #ifndef __ObjectiveCPlus__File__ #define…
user2125861
1
vote
3 answers

Looking to round the final answer to 2 decimals C++

I'm trying to round my final answer to 2 decimals so it is Dollars and Cents. I'm new to coding, and can't figure it out. I want to round "w" in the line that says "The amount you need to charge is" Here's my code: #include using…
Godzdude
  • 115
  • 1
  • 2
  • 7
1
vote
7 answers

Why using while(!input.eof()) loop twice not working?

On the following lines of code is intended to put every words in the input text file(words are separated by new lines) to a vector of strings, then to turn each word inside out, and to see if this turned word is contained in the list of words in the…
Eric
  • 2,635
  • 6
  • 26
  • 66
1
vote
1 answer

in boost iostream filtering_ostream, what is the difference between sync(), strict_sync() and flush()?

considering a simple counting filter: class CountableOstreamFilter : public boost::iostreams::multichar_output_filter { public: CountableOstreamFilter(): m_written(0) { } template std::streamsize write(Sink& dest,…
Aviad Rozenhek
  • 2,259
  • 3
  • 21
  • 42
1 2 3
99
100