Questions tagged [istream]

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

696 questions
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,642
  • 1
  • 16
  • 22
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
  • 32,570
  • 22
  • 121
  • 229
8
votes
2 answers

Checking count of bytes read by istream::read()

Is there posibility (any method) to check count of bytes read by function presented below: istream& read (char* s, streamsize n);
CppMonster
  • 1,216
  • 4
  • 18
  • 35
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
1 answer

input iterator skipping whitespace, any way to prevent this skipping

I am reading from a file into a string until I reach a delimitting character, the dollar symbol. But the input iterator is skipping whitespace so the string created has no spaces. not what I want in this case. Is there any way to stop the…
Angus Comber
  • 9,316
  • 14
  • 59
  • 107
8
votes
3 answers

FILE * and istream: connect the two?

Suppose I "popen" an executable, I get a FILE* in return. Furthermore, suppose I'd like to "connect" this file to an istream object for easier processing, is there a way to do this?
jldupont
  • 93,734
  • 56
  • 203
  • 318
8
votes
2 answers

C++ how does While( cin >> x) work?

My question is how does, while(cin>>x) { //code } work. Or to be more specific, what about that code halts the loop? From the documentation here, it looks like the >> operator returns a &istream. Does that mean if the read fails or hits the…
Dan
  • 2,625
  • 7
  • 39
  • 52
7
votes
4 answers

substream from istream

Suppose I have an ifstream which represents a large file containing lots of sub-files aggregated together. I want to be able to create a "sub" istream from the larger ifstream (given a size and offest) representing a part of the file so other code…
Justin Meiners
  • 10,754
  • 6
  • 50
  • 92
7
votes
3 answers

ifstream's operator>> to detect end of line?

I have an irregular list where the data look like this: [Number] [Number] [Number] [Number] [Number] [Number] [Number] [Number] [Number] [Number] [Number] [Number] [Number] [Number] [...] Notice that some lines have 2 numbers, some have 3…
Bonk
  • 1,859
  • 9
  • 28
  • 46
7
votes
1 answer

istream::tellg() returns -1 when used with my custom streambuf class?

I'm trying to create an istream that reads directly from a raw memory buffer. I found a nice way to do this in another post on here: class membuf : public basic_streambuf { public: membuf(char* p, size_t n) { setg(p, p, p…
EdSanville
  • 113
  • 7
7
votes
2 answers

std::getline alternative when input line endings are mixed

I'm trying to read in lines from a std::istream but the input may contain '\r' and/or '\n', so std::getline is no use. Sorry to shout but this seems to need emphasis... The input may contain either newline type or both. Is there a standard way to do…
spraff
  • 32,570
  • 22
  • 121
  • 229
7
votes
3 answers

Easiest way to read a null terminate string with istream?

I have an istream and i need to read exactly a specific amount of bytes BUT i dont know the length of it. It is null terminated. I was thinking i could either 1) Write a loop and read one byte at a time 2) Tell it to return me a buffer or string…
user34537
7
votes
3 answers

Find the end of stream for cin & ifstream?

I'm running myself through a C++ text book that I have as a refresher to C++ programming. One of the practice problems (without going into too much detail) wants me to define a function that can be passed ifstream or cin (e.g. istream) as an…
user435219
  • 73
  • 1
  • 1
  • 4
7
votes
2 answers

How to implement custom std::streambuf's seekoff()?

I have the following implementation based on e.g. this question and answer struct membuf : std::streambuf { membuf(char* begin, char* end) { this->setg(begin, begin, end); } protected: virtual pos_type seekoff(off_type off, …
Patryk
  • 22,602
  • 44
  • 128
  • 244
7
votes
1 answer

How do I implement seekg() for a custom istream/streambuf?

I used to be a C++ expert a decade ago, but for the past 10 years I've been programming Java. I just started a C++ project that uses a small third-party XML parser. The XML parser accepts an STL istream. My XML data is coming from a Windows COM…
Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
1 2
3
46 47