711 questions
1 vote
1 answer
85 views
Read-and-validate istream equivalent to fscanf
I have a very simple scenario that looks like std::ifstream file("myfile.txt"); std::string discard; int num; file >> discard >> num; // to consume e.g. HEADER 55 Despite all ...
2 votes
1 answer
60 views
std::istreambuf_iterator equality when using seekg
I am puzzled by the output of the code below: std::string content = "abcdefghijklmnopqrstuvwxyz1234567890"; std::istringstream iss(content); iss.seekg(10); std::istreambuf_iterator<char&...
0 votes
0 answers
118 views
How I can "convert" IStorage to a byte array or to an IStream?
I have implemented a drag-and-drop receiver (C++, WINAPI). It allows me to get a storage with a dragged object (OLE IStorage object). I need to "convert" it to a byte array (something like a ...
1 vote
1 answer
106 views
Validating istream with std::ios_base::iostate
I have to write a stream extraction operator>> function which checks if the istream variable (stream) in the parameter is valid before returning it along with a delimiter (which is already ...
1 vote
0 answers
48 views
Why is EOF triggering on the last word instead of after trying to reget input?
So currently working on some exercises on I/O, my code basically takes a string from input and removes the vowels at input: ExerciseClass.cpp: NoVowelString& NoVowelString::operator>>(std::...
1 vote
2 answers
99 views
C++ - Why does the cin inside the if statement get skipped over when it is under a while loop reading an unknown number of inputs?
My code skipped over the cin under the while loop reading an unknown number of inputs. I wanted to run the code int curval = 0, val = 0; while(std::cin >> curval){ val++; } ...
0 votes
0 answers
77 views
Is it possible to pass std::cin to a function wanting an iostream?
I am using a library that has a function taking an iostream for a data stream, but I want to pass std::cin. It apparently is not possible to pass an istream to an iostream, but is there way around ...
-1 votes
2 answers
118 views
Can an std::istream be split without specifying the number of delimiters?
I have the separate_by_delimiter function which is used inside another function outside_func std::vector<std::string> separate_by_delimiter(std::istream &input, int num_separators, char ...
0 votes
1 answer
87 views
Is there a unget() method for putting back everything extracted by std::getline back into an istream?
I am extracting each full row of a csv file using std::getline: for (std::string row; std::getline(is, row); ) // reads entire row in csv file { if (std::ranges::count(row, ',') != Temp_reading::...
1 vote
2 answers
126 views
Why does `std::istream::seekg()` affect the behavior of `std::istreambuf_iterator`?
Why does std::istream::seekg() affect the behavior of std::istreambuf_iterator? I carefully read the introduction about std::istreambuf_iterator on cppreference, but there is no direct answer for this ...
0 votes
2 answers
91 views
No output from class method
The code: #include<iostream> #include<vector> #include<numeric> using namespace std; class Point{ double m_x,m_y; public: Point(double x=0,double y=0):m_x(x),m_y(y){} Point ...
1 vote
0 answers
42 views
istreambuf_iterator potential null pointer deref [duplicate]
In the following code: std::string fn() { std::ifstream ifs {"bob", std::ios::in | std::ios::binary}; auto beg = std::istreambuf_iterator<char>(ifs); auto end = std::...
0 votes
1 answer
54 views
How to read a file that is given from NodeJS to a c++ process using stdin?
I created a C++ program that uses a method of a library. This method needs an istream to work. The C++ compiled program is executed using child_process module of NodeJS and the file is sent to the c++ ...
0 votes
0 answers
23 views
"no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'Diem2D')"
enter image description here i tried to used operator istream and ostream but it doesn't work. I'm writing a HinhTron class from the existing Diem2D class to use point coordinates from the 2D class. ...
0 votes
1 answer
111 views
Template default argument missing with basic_istream class
I was checking the implementation of the basic_istream class. I found the implementation at https://gcc.gnu.org/onlinedocs/gcc-13.2.0/libstdc++/api/a00113_source.html#l00095. Let me add a snippet. I ...