Questions tagged [istringstream]

Anything related to C++ `istringstream` standard library class. This class represents an "input string stream", i.e. an input stream that allows a string to be used as the source of information attached to the stream.

Anything related to C++ istringstream standard library class. This class represents an input string stream, i.e. an input stream that allows a string to be used as the source of information attached to the stream.

istringstream is a specialization of the basic_istringstream template class and it is defined in C++ <sstream> standard library header.

See CPPreference.com on basic_istringstream template class.

216 questions
1
vote
1 answer

how to customize the delimiter in std::getline

I was solving attribute parser on hackerRank but I am stuck with delimiter. I want to grab an element from ("any thing"), in this case it will give me (any thing), but when I do this: while (getline(ob, item, '""')) {//but its be true when i put…
1
vote
0 answers

C++ issue with istringstream and reading floats

I'm trying to read strings and floats from stdin but I'm running into a weird issue. When reading certain characters the input is "consumed" and lost before being read as a string. I'm expecting that any characters would flip the fail bit and then…
1
vote
3 answers

C++ istringstream in loop not changing its value

I'm fairly new to c++ and have encountered a problem where by searching alone I couldn't find a solution. The problem is, why does the istringstream never changes its value inside the loop below? It takes the value from dirs[ 0 ] and dirs[ 1 ] and…
zhade
  • 11
  • 2
1
vote
1 answer

C++ How does istringsteam work?

For my homework, I am using std::istringstream in order to create error messages when applicable. My program works fine, except for two certain cases, it does not work properly. The first test case is when the second number is zero and the first…
Phil Cho
  • 131
  • 3
  • 14
1
vote
1 answer

Extracting file names from text file

I need to extract file names with their extension from an input text file to a string vector. The input text file is quite messy and serves as configuration file for some application. What I know about the file names I am trying to extract is they…
hamza keurti
  • 385
  • 1
  • 2
  • 15
1
vote
1 answer

Fivefold output from istringstream

I would like to outout each line after a certain substring is detected. Somehow I get a fivefold output for iss. Here's my code: //load all data from txt string data; std::ifstream infile("SavedData.txt"); while…
user8331308
1
vote
1 answer

modify number of variables in istringstream

I need to get input in a line based on a modifiable number of variables that are determined from an earlier input. If the input you get in an earlier function is 1, the the code would be like std::string istring; std::getline(std::cin,…
fishyperil
  • 35
  • 6
1
vote
2 answers

C++: stringstream parsing

I am looking for an easy and elegant way for parsing numbers (dec and hex) with stringstream (or istringstream or some other Std-C++ class). Valid input for a decimal number of e.g. 11 should be 11 0xb bh Normally I would use a regular expression…
chris01
  • 10,921
  • 9
  • 54
  • 93
1
vote
2 answers

Passing string to istringsream argument of a function

I would like to work with istringstream within a function and I want the istringstream to be initialized by a string passed by value. Can I avoid the explicit istringstream iss_input(string_input); in the function body? void f(istringstream…
Slazer
  • 4,750
  • 7
  • 33
  • 60
1
vote
1 answer

C++ Reading ints as unsigned chars using istringstream

When using std::istringstream to read gray pixel values from a file (0-255), I notice a strange behavior and I can't understand what is happening. To conserve memory, I want to read these values into unsigned chars (since they have the same 0-255…
user2600959
  • 229
  • 4
  • 12
1
vote
2 answers

C++ getline()'s undocumented behavior

In C++ when you use getline() with delimiter on stringstream there are few things that I didn't found documented, but they have some non-error handy behaviour when: delimiter is not found => then simply whole string/rest of it is returned there is…
jave.web
  • 13,880
  • 12
  • 91
  • 125
1
vote
1 answer

istream manipulators for reading double

I need to read numbers like 14.3925125E from istringstream as part of formatted input. E meaning east, not scientific notation. When I try to use input >> double >> char it looks like the stream takes the number as wrong scientific and fails. I…
bajermi2
  • 418
  • 1
  • 5
  • 14
1
vote
0 answers

getline stops reading files after text file has multiple spaces

Hello I am new to stackoverflow so please pardon any newbie mistakes I make. I have a program I am trying to build in c++ and I am running into some problems. This program is supposed to let the user input a file name and then read the file and…
ejs
  • 11
  • 2
1
vote
2 answers

C++ Piping ifstream into stringstream

I am overloading my istream operator, so I can replace std::cin with my object. I know I will have to feed it an empty stringstream for the final output to work. I would like to feed an std::ifstream into a std::stringstream as so: while(ifs >> ss)…
scx
  • 3,221
  • 1
  • 19
  • 37
1
vote
2 answers

I need help on my reverse polish notation calculator

I am working on a program to make a reverse polish notation calculator and I am wondering if anyone can give me some hints. The calculator will intake a single line from the user like 2 3 + 7 4 - *; with spaces in between and I am suppose to print…
Hi_mynameis
  • 11
  • 1
  • 3