Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
86 views

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 ...
avigt's user avatar
  • 602
2 votes
1 answer
62 views

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&...
Chen's user avatar
  • 330
0 votes
0 answers
121 views

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 ...
LUN's user avatar
  • 359
1 vote
1 answer
112 views

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 ...
Cevapi Man69's user avatar
1 vote
0 answers
48 views

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::...
user27170131's user avatar
1 vote
2 answers
99 views

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++; } ...
David Lee's user avatar
0 votes
0 answers
77 views

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 ...
Robert Heller's user avatar
-1 votes
2 answers
120 views

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 ...
Pedi Alz's user avatar
0 votes
1 answer
87 views

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::...
a_floating_point's user avatar
1 vote
2 answers
127 views

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 ...
John's user avatar
  • 3,574
0 votes
2 answers
91 views

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 ...
Cat Ball's user avatar
1 vote
0 answers
42 views

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::...
code_fodder's user avatar
  • 16.7k
0 votes
1 answer
54 views

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++ ...
AlbertDeTerre's user avatar
0 votes
0 answers
25 views

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. ...
bazzi's user avatar
  • 1
0 votes
1 answer
114 views

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 ...
Hardik's user avatar
  • 187
3 votes
2 answers
213 views

I was trying to get all words (sequence of non whitespace characters) out of a file. In trying to do so, I accidently created an infinite loop, because at the end of the file, no more word is ...
0xbachmann's user avatar
  • 1,088
0 votes
0 answers
202 views

Suppose I have two APIs that I need to interact with: API 1 is a producer which provides me with a raw character buffer (const char*) and a length (say std::size_t). API 2 is a consumer which expects ...
Luatic's user avatar
  • 11.3k
4 votes
1 answer
293 views

Consider this code snippet (adapted from cppreference.com): constexpr std::string_view text{"Hello-+-C++-+-23-+-!"}; constexpr std::string_view delim{"-+-"}; std::ranges::for_each(...
einpoklum's user avatar
  • 138k
-2 votes
3 answers
125 views

I have a class of shapes, it works on the principle that a shape consists of points (x and y coordinates). But overloading the input and output operators I encountered a problem that could serve as an ...
keinpop's user avatar
1 vote
1 answer
61 views

I'm writing an adapter between different libraries in C++20. I reached a part where I get a std::istream from one library and pass it to the second library, which also takes std::istream. The problem ...
Felix.leg's user avatar
  • 843
3 votes
0 answers
221 views

Win32 MFC I can load an icon stream (to use with WebView2) from a physical ICO file on my hard drive. Eg: wil::com_ptr<IStream> iconStreamPdfSettings; CHECK_FAILURE(SHCreateStreamOnFileEx( L&...
Andrew Truckle's user avatar
2 votes
0 answers
81 views

Is the following code prone to undefined behavior when end of file or an empty line is provided as input? unsigned long long i; cin >> i; From what I've observed using Compiler Explorer, it ...
ByteEater's user avatar
  • 1,201
1 vote
1 answer
343 views

Consider the following piece of code (out of context for the sake of simplicity): std::unique_ptr<std::istream> stream; stream = std::make_unique<std::ifstream>(path, std::ios::in | std::...
Kaiyakha's user avatar
  • 2,075
0 votes
2 answers
258 views

I am trying to read (x,y) floating point values from a txt file in C++. The numbers are separated by a space. The ith number and the i+1th number make the (x,y) coordinates. So index positions 0 and 1 ...
Happy Classics's user avatar
0 votes
1 answer
80 views

What is the best way to make a program that reads the elements from the input until the EOF and returns the container of read elements? This is what I have to do p.h file: #pragma once #include <...
Xavi's user avatar
  • 67
2 votes
0 answers
41 views

I have a binary tree that takes in a stream of words and adds them each to a new node of the binary tree, skipping duplicates. I tried implementing an input method like so: void WordTree::input(std::...
Hofbr's user avatar
  • 1,020
0 votes
0 answers
29 views

My program takes in a student's last name, then first name, then midterm score 1, then midterm score 2, and lastly their final score. Based on the average of their midterm scores and their final score ...
Nicholas Davies's user avatar
3 votes
3 answers
127 views

I have this simple function that, given a string str, if it is a number then return 'true' and overwrite the reference input num. template <typename T> bool toNumber(string str, T& num) { ...
GiaMat45's user avatar
0 votes
0 answers
410 views

Given a string of which the content could be "this is a test string jump‎ ‏‏‎ ‎‎fox string". There are 2 things to note from this string - there is one space between every word, but also at ...
Mutlithrd's user avatar
-1 votes
1 answer
84 views

Here's my fraction class: class fraction { // type definition int num; int denom; ostringstream sstr; public: fraction(int c=0, int d=1) : num(c), denom(d) { sstr = ...
Marc Miller's user avatar
-1 votes
2 answers
545 views

I currently have some .bin files, each of which contains a matrix of size AxBxC. I would like to load it into a 3d vector vector<vector<vector<float>>> in C++, but encountered some ...
Ziggy1209's user avatar
1 vote
1 answer
97 views

I have class Address nested in class Student, and I want to feed each input line into the class Student with operator>> overloading through istream. class Address { public: .... private: ...
Yifangt's user avatar
  • 171
16 votes
2 answers
3k views

I am reading Bjarne Stroustrup's "Programming Principles and Practice Using C++" (second edition). On page 660-661, the writers define a function as follows: istream& read_word(istream&...
CPPL's user avatar
  • 846
1 vote
2 answers
221 views

can you help me Why this code can't be swap cout << "Enter a string: "; getline(cin, str1); cout << "Enter another string: "; cin.get(str, 100, '\n'); ...
Nicholas Martin's user avatar
1 vote
1 answer
257 views

I am trying to modify the ICMP boost_asio implementation to print ICMP response and request packets. In the example code I am trying to print the response/reply buffer using below code: void ...
vishal kumar's user avatar
2 votes
2 answers
1k views

I want to take input from an istream from either a std::ifstream or std::cin depending on some condition. As far as I can get it working, I had to use a raw std::istream* pointer: int main(int argc, ...
bigyihsuan's user avatar
0 votes
1 answer
640 views

I need to make a custom istream manipulator that reads 5 characters from input, then skip 5 characters from input, and does it to the end of the string. Example: string line; cin >> skipchar >...
nameses's user avatar
1 vote
1 answer
399 views

Is there a propper way in an isstrinstream to skip/ ignore the next, or even the next n words? The possibility to read n times a variable seems to work, but is very clunky: for (int i = 0; i < n; ++...
Moritz's user avatar
  • 426
1 vote
1 answer
125 views

In C++ (and using the standard library facilities), if I want to read an integer from the standard input, I need to do this: int x; std::cin >> x; And looking at the std::istream page on ...
einpoklum's user avatar
  • 138k
2 votes
1 answer
748 views

I'm working on some OOP code and was trying to setup a istream& with the operator >>. But with the code that I have, I keep getting an error, like the one stated above in the title. The code ...
Slash's user avatar
  • 101
0 votes
1 answer
59 views

Let's say you have std::array<int, SIZE> a, and you have saved each element of a into a file in one line separated by a space. Then you want to read them with a std:istream& is via: is >&...
prestokeys's user avatar
  • 4,849
0 votes
0 answers
239 views

I have the following code. What I'm trying to do is implement a word count function similar to wc in unix. It takes a file as input and gives back the number of lines, words and characters in that ...
r3k0j's user avatar
  • 187
0 votes
1 answer
135 views

The code i am trying to run is given below. Here in line 9 I am trying to take multiple inputs using the while(cin>>n) method. The input I gave is like : 2 4 5 6 45 357 3 (ctrl+z)(ctrl+z) to ...
Dhruv's user avatar
  • 2
1 vote
1 answer
454 views

i want to use : Rslt := WrapCompressedRTFStream(OleStream, 0, Uncompressed); where : OleStream, Uncompressed : IStream; and RTFStringIn RTFStringOut are String; i have the RTFStringIn (As String). ...
mazluta's user avatar
  • 99
0 votes
0 answers
78 views

I've recently had to implement the common pattern of reading from a file or, given a filename of "-", from stdin. There is an abundance of solutions on SO, but I found mine to be shorter. ...
mafu's user avatar
  • 33k
-1 votes
3 answers
3k views

Hello I'm relatively new to operator overloading, but I do believe its the answer to a problem i've been facing in almost every program I make. My goal is to overload std::cin >> int_var so ...
Cod Pod Tracks's user avatar
-2 votes
1 answer
116 views

I tried to play with some code to test overloading functions. The overloading part went well, however, I learned something about std::cin that made me feel stupid for not noticing it before! #include &...
med amine riahi's user avatar
0 votes
2 answers
8k views

I am completely new to the c++ and I have problem with managing input. I have a program where I want to be possible to read input from console but also from the file. I have class with private field ...
Riomare's user avatar
  • 85
0 votes
2 answers
157 views

I am a beginner in C++. What is the correct way to call a function that expects std::istream&? Tried it with read(std::cin);, but I get an error from the compiler. typedef double Element; ...
petrea77's user avatar
-1 votes
1 answer
27 views

Thanks for the help. My program reads lines from stdin. The first one has a single number which determines the mode at which the program is running, and the rest contain sequences of numbers of ...
Javier de Muller Santa-María's user avatar

1
2 3 4 5
15