Questions tagged [istream]

In C++ std::istream is the base class for input streams.

658 questions
11
votes
2 answers

Shouldn't istream::peek() always return what you just putback()?

Intuitively, judging from the C++ spec, it looks to me as if istream::putback( c ) should always arrange the input buffer such that the next call to istream::peek() should read the character c. Is this not correct? I ask because the latest version…
OldPeculier
  • 9,811
  • 8
  • 42
  • 71
10
votes
2 answers

How to use istream with strings

I would like to read an file into a string. I am looking for different ways for how to do it efficiently. Using a fixed size *char buffer I have received an answer from Tony what creates a 16 kb buffer and reads into that buffer and appends the…
hyperknot
  • 12,019
  • 22
  • 87
  • 143
10
votes
2 answers

Can `std::istream::operator>>()` accept integer radix prefixes like stdio's %i format specifier?

When using scanf() and its variants, the format specifier %i will accept data as hex (prefixed "0x"), octal (prefixed "0"), or decimal (no prefix), so for example the strings "0x10", "020", and "16" are all converted to an integer with decimal value…
Clifford
  • 76,825
  • 12
  • 79
  • 145
9
votes
2 answers

How can I find out how many bytes are available from a std::istream?

If I wanted to read() the content of a std::istream in to a buffer, I would have to find out how much data was available first to know how big to make the buffer. And to get the number of available bytes from an istream, I am currently doing…
edam
  • 718
  • 1
  • 8
  • 13
9
votes
2 answers

Why is there no std::from_string()?

Why is there no template T std::from_string(const std::string& s); in the C++ standard? (Seeing how there's an std::to_string() function, I mean.) PS - If you have an idea for the reason this was not adopted/considered, just…
einpoklum
  • 86,754
  • 39
  • 223
  • 453
9
votes
1 answer

Why does operator>> on complex not set eofbit if it reaches EOF?

I'm trying to read as many std::complex as possible from a file (or any std::istream). If the operation fails, I check for ios::eof(). If it hasn't been set, I assume that there was an error in parsing the data, and I can report to the user…
dennis
  • 193
  • 6
9
votes
1 answer

What Effect Would LWG2349 Have?

While libstdc++ does not, libc++ does follow the standard which states that passing ios_base::failbit to basic_istream::exceptions has no effect on formatted input. For example this code: istringstream is{"ASD"}; double…
Jonathan Mee
  • 35,107
  • 16
  • 95
  • 241
9
votes
1 answer

How to store formatting settings with an IOStream?

When creating formatted output for a user defined type it is often desirable to define custom formatting flags. For example, it would be nice if a custom string class could optionally add quotes around the string: String str("example"); std::cout <<…
Dietmar Kühl
  • 141,209
  • 12
  • 196
  • 356
9
votes
1 answer

C# IStream implemenation of IStream

First of all this is no duplicate of this Does a wrapper class for a COM interop IStream already exist? because I need the implemenation in the other direction. I need to create an IStream implemenation from IO.Stream to IStream. But before I start…
Florian
  • 5,728
  • 3
  • 41
  • 75
8
votes
4 answers

istream eof discrepancy between libc++ and libstdc++

The following (toy) program returns different things when linked against libstdc++ and libc++. Is this a bug in libc++ or do I not understand how istream eof() works? I have tried running it using g++ on linux and mac os x and clang on mac os x,…
zaphoyd
  • 2,412
  • 1
  • 13
  • 19
8
votes
4 answers

Is it reasonable to take std::istream&& as a argument?

I have encountered code which does this: SomeObject parse (std::istream && input) {.... The input argument is an rvalue reference, which normally means the function is intended to take ownership of the argument. That's not quite what is happening…
spraff
  • 29,265
  • 19
  • 105
  • 197
8
votes
3 answers

C++ std::istream readsome doesn't read anything

It's like readsome isn't even reading. Returns 0 and doesn't read any chars. What is wrong here? #include #include int main () { std::fstream stream("list.cpp", std::ios::in); if (stream.good() || !stream.bad() ||…
Samuel Danielson
  • 4,351
  • 2
  • 30
  • 31
8
votes
1 answer

boost::lexical_cast not recognizing overloaded istream operator

I have the following code: #include #include struct vec2_t { float x; float y; }; std::istream& operator>>(std::istream& istream, vec2_t& v) { istream >> v.x >> v.y; return istream; } int…
Colin Basnett
  • 3,735
  • 1
  • 27
  • 46
8
votes
1 answer

Discrepancy between istream's operator>> (double& val) between libc++ and libstdc++

With my recent upgrade to Mac OS X 10.9 the default standard C++ library changed from libstdc++ to libc++. Since then I observe unexpected behaviour of the stringstream operator>>(double) documented in the code example below. In summary the libc++…
Stephan Aiche
  • 81
  • 1
  • 3
8
votes
2 answers

how can I convert istream * to string or just print it?

The below function part of connector/C++, it returns a istream*. if i just try and print it, it shows hex or a memory location because its a * type. istream *stream = res->getBlob(1); I tried to read & print it with this: string s; while…
user1397417
  • 658
  • 4
  • 10
  • 34
1
2
3
43 44