In C++ std::istream is the base class for input streams.
Questions tagged [istream]
658 questions
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?
![](../../users/profiles/171461.webp)
jldupont
- 82,560
- 49
- 190
- 305
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…
![](../../users/profiles/839501.webp)
Dan
- 2,369
- 6
- 36
- 50
7
votes
2 answers
Conveniently copy std::vector to input stream (std::istream) object
I'm trying to make use of a function which comes in a 3rd party lib and expects an input stream object in which binary file data is transported.
Signature looks like that:
doSomething(const std::string& ...,
const std::string& ...,
…
![](../../users/profiles/1220543.webp)
Rip-Off
- 318
- 4
- 13
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…
![](../../users/profiles/830469.webp)
Bonk
- 1,669
- 7
- 26
- 44
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…
![](../../users/profiles/854161.webp)
EdSanville
- 103
- 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…
![](../../users/profiles/458742.webp)
spraff
- 29,265
- 19
- 105
- 197
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
6 answers
How to assign istringstream and ifstream to an istream variable?
I want to have a variable of type istream which can hold either the contents of a file or a string. The idea is that if no file was specified, the variable of type istream would be assigned with a string.
std::ifstream…
![](../../users/profiles/3895469.webp)
oddRaven
- 552
- 5
- 18
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…
![](../../users/profiles/435219.webp)
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,
…
![](../../users/profiles/675100.webp)
Patryk
- 18,244
- 37
- 110
- 212
7
votes
4 answers
Read from cin or a file
When I try to compile the code
istream in;
if (argc==1)
in=cin;
else
{
ifstream ifn(argv[1]);
in=ifn;
}
gcc fails, complaining that operator= is private. Is there any way to set an istream to different values based on a…
![](../../users/profiles/271317.webp)
m42a
- 1,192
- 2
- 9
- 14
7
votes
2 answers
How to check if there is anything in cin [C++]
is there any way to check if there is something in cin? I tryied peek() but if there isn't anything peek() waits for input and that isn't what I want.
Thank you
![](../../users/profiles/207177.webp)
There is nothing we can do
- 21,267
- 27
- 92
- 184
7
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…
![](../../users/profiles/619818.webp)
Angus Comber
- 8,150
- 10
- 49
- 92
7
votes
1 answer
Is this a compiler bug or it's my code?
Here is a sample code:
#include
#include
#include
#include
#include
using std::cout;
using std::endl;
std::size_t const BUF_SIZE(1000);
std::ostream& operator<<(std::ostream& os, std::tm const&…
![](../../users/profiles/975403.webp)
Reza Toghraee
- 1,535
- 1
- 12
- 21
6
votes
5 answers
Parsing only numbers from istream in C++
I have a bunch of input files that look like the following:
(8,7,15)
(0,0,1) (0,3,2) (0,6,3)
(1,0,4) (1,1,5)
I need to write a function that parses these inputs one number at a time, so I need to be able to separate the input by numbers, e.g.: 8,…
![](../../users/profiles/901870.webp)
Arvin
- 1,307
- 2
- 19
- 31