In C++ std::istream is the base class for input streams.
Questions tagged [istream]
658 questions
6
votes
1 answer
Calling putback() on istream multiple times
Many sites describe the istream::putback() function that lets you "put back" a character into the input stream so you can read it again in a subsequent reading operation.
What's to stop me, however, from calling putback() multiple times in sequence…
![](../../users/profiles/353338.webp)
Izhido
- 353
- 3
- 10
6
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…
![](../../users/profiles/421049.webp)
Garret Wilson
- 14,167
- 20
- 115
- 211
6
votes
3 answers
How can you pass an std::istream into a function in a way that allows to pass temporaries?
I am trying to create a constructor to load a resource from any istream given to it. I cannot seem to figure out the best way to pass the istream parameter into a constructor.
Loader::Loader(istream stream);
This one is obviosly bad due to object…
![](../../users/profiles/2164642.webp)
Tobias
- 834
- 8
- 18
6
votes
1 answer
Concurrency problems wih Boost Property tree
I developed a simple wrapper that encapsulates a JSONObject with Boost Property trees.
The problem is a segmentation fault in this code:
void JSONObject::parse(const std::string &text)
{
std::istringstream ss(text);
…
![](../../users/profiles/1236117.webp)
mariolpantunes
- 1,073
- 2
- 13
- 27
6
votes
2 answers
GCC 4.7 istream::tellg() returns -1 after reaching EOF
The following code works with gcc 4.4.
But gcc 4.7 will give assertion failure.
#include
#include
#include
using namespace std;
int main()
{
string input("abcdefg");
stringstream iss(input);
…
![](../../users/profiles/835887.webp)
John Crane
- 341
- 5
- 13
5
votes
4 answers
istream extraction operator: how to detect parse failure?
How can I detect whether the istream extraction failed like this?
string s("x");
stringstream ss(s);
int i;
ss >> std::ios::hex >> i;
EDIT -- Though the question title covers this, I forgot to mention in the body: I really want to detect whether…
![](../../users/profiles/6610.webp)
xtofl
- 38,207
- 10
- 95
- 177
5
votes
0 answers
C++ changin istream
I am learning C++ at the moment and am working to understand streams. Today I learned this really cool thing, you can split a string stream into multiple floats/integers, like:
#include
#include
using namespace std;
int main()…
![](../../users/profiles/1051438.webp)
Robin Dorstijn
- 81
- 5
5
votes
0 answers
Read from stream Hex Float
I am trying to read a hex float value through std::cin. However, it just reads in 0. Here is my code so far:
#include
#include
int main() {
double f = 0.0;
std::cout << ">";
std::cin >> std::hexfloat >> f;
std::cout <<…
![](../../users/profiles/5206626.webp)
Arden Rasmussen
- 99
- 9
5
votes
4 answers
Understanding the design of std::istream::read
std::istream has the prototype istream& read (char* s, streamsize n) the actual number of bytes read should be gotten by calling istream::gcount(), also the validity of the istream can be known from ios::good.
I was discussing another stream class'…
![](../../users/profiles/183120.webp)
legends2k
- 27,643
- 22
- 108
- 196
5
votes
4 answers
"carbon-copy" a c++ istream?
For my very own little parser framework, I am trying to define (something like) the following function:
template
// with operator>>( std::istream&, T& )
void tryParse( std::istream& is, T& tgt )
{
is >> tgt /* , *BUT* store every…
![](../../users/profiles/266614.webp)
srs
- 400
- 3
- 9
5
votes
1 answer
Can one read a remote file as an istream with libcurl?
I'd like to use the libcurl library to open a remote date file and iterate through it with an istream. I've looked through the nice example in this thread but it writes the remote file to a local file. Instead I'd like to have the remote reads be…
![](../../users/profiles/364670.webp)
jobu
- 93
- 4
5
votes
5 answers
What's the difference between getline and std::istream::operator>>()?
#include
#include
using namespace std;
int main()
{
string username;
cout<< "username" ;
cin >> username;
}
So I was curious on what's the difference between these two codes, I heard it's the same thing but if it is…
![](../../users/profiles/4857442.webp)
user4857442
- 59
- 1
- 1
- 4
5
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);
![](../../users/profiles/2282746.webp)
CppMonster
- 1,056
- 3
- 14
- 33
5
votes
2 answers
Reading SDL_RWops from a std::istream
I'm quite surprised that Google didn't find a solution. I'm searching for a solution that allows SDL_RWops to be used with std::istream. SDL_RWops is the alternative mechanism for reading/writing data in SDL.
Any links to sites that tackle the…
![](../../users/profiles/233522.webp)
Kornel Kisielewicz
- 51,225
- 12
- 100
- 147
5
votes
3 answers
C# and IStream.Read
I'm trying to use System.Runtime.InteropServices.ComTypes.IStream from C#, but I'm having some trouble. According to MSDN, the C# definition looks like this:
void Read(
byte[] pv,
int cb,
IntPtr pcbRead
)
Basically, I can read data…
![](../../users/profiles/171536.webp)
Jeff Godfrey
- 668
- 8
- 16