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
2
votes
2 answers

Why do std::istringstream only work here with a constructor?

The code below compiles and works as expected. On line 11, when I change std::istringstream iss(temp) to std::istringstream iss() , it stops working. An error occurs on line 18, iss.str(temp): expression must have class type but it has type…
BrianZhang
  • 153
  • 1
  • 8
2
votes
2 answers

Problem reading file and storing it in unordered_map

I'm trying to read a file and store it's content into an unordered_map but I've got a little problem. This is my unordered_map: std::unordered_map> _users; And this is the content of the file that I'm trying to…
MM1
  • 912
  • 1
  • 10
  • 28
2
votes
1 answer

How to skip the space and the new line from stringstream and put them in a vector?

I'm trying to read a text file that contains information of a person (name, age, occupation) as follows: name 20 occupation name 25 occupation name 34 occupation I read the whole file and for each line I used istringstream to skip the space between…
KingAzaiez
  • 103
  • 7
2
votes
0 answers

Inserting and extracting numeric_limits::infinity in a stream

The following program apparently shows an inconsistency when writing and reading on a std::stringstream a double set to "infinity", using std::numeric_limits::infinity. #include #include #include #include…
francesco
  • 7,189
  • 7
  • 22
  • 49
2
votes
1 answer

Extract the coefficients of a polynomial with istringstream c++

currently i'm working on a project (namely, creating a class of a polynomial) and i've already implemented the "add-subtract-divide-and-so-on" methods. But i'm stuck on a method to pass from a string like that 3x^1-2x^4 to a vector of coefficients…
alienflow
  • 400
  • 7
  • 19
2
votes
1 answer

Using stringstream to print number but when i included, for example 1.3067d, but it still print 1.3067

#include #include #include using namespace std; int main() { istringstream iss("2.832 1.3067d nana 1.678"); double num = 0; while(iss >> num || !iss.eof()) { if(iss.fail()) { …
2
votes
2 answers

getline keeps waiting on standart input

So I've been pulling my hair out about this since yesterday, I've checked multiple posts on here trying to figure this out, basically, I'm trying to read 1 or more lines from standard input into a string variable then use an istringstream to get…
user3229557
2
votes
1 answer

How to read a word from std::istringstream without assigning to a tmp variable through >>?

I have a std::string line which contains a line of text read from a file. I then create a istringstream: std::istringstream str(line); to read this line. To get the first word, I do this: std::string word; str >> word; Is there a way to get the…
a06e
  • 18,594
  • 33
  • 93
  • 169
2
votes
0 answers

How to achieve the maximum field width feature of sscanf via istringstream in C++?

I know it is possible to use istringstream as an alternative to sscanf, for example: std::istringstream argtime{"01:00"}; char colon; int hour; int minute; argtime >> std::noskipws; argtime >> hour >> colon >> minute; if(argtime && colon == ':') //…
Sadeq
  • 7,795
  • 4
  • 34
  • 45
2
votes
2 answers

Initializing "const std::string" from "std::istringstream"

I'm trying to parse a file which is in KeyValue format. I'm reading the file lines in an std::istringstream object, and I'm extracting a Key string from it. I want to avoid accidentally changing the value of this Key string by making it…
hkBattousai
  • 10,583
  • 18
  • 76
  • 124
2
votes
3 answers

CPP : Parsing String Stream is too slow

My cpp code needs to read a 7 MB text file of space separated float values. It's taking about 6 seconds to parse the string values into a float array, which is too much for my use case. I've been checking online and people say it is usually the…
masupial
  • 29
  • 4
2
votes
3 answers

Using QFile made istringstream as binary input (for libpng)

I am attempting to use libpng in order to read a png from a Qt resource. The catch: The class doing the reading should not have any dependencies of Qt. In a first step, reading…
Markus-Hermann
  • 789
  • 11
  • 24
2
votes
2 answers

istringsteam with line breaks

Okay I read that if we have a string s =" 1 2 3" we can do : istringstream iss(s); int a; int b; int c; iss >> a >> b >> c; Lets say we have a text file with the following : test1 100 ms test2 200 ms test3 300 ms ifstream in…
Tharwat Harakeh
  • 89
  • 1
  • 3
  • 11
2
votes
0 answers

counting length of string token using istringstream

I'm getting an error saying no matching function for call to 'getline' involving the getline(tokenizer, " "); Im not sure how to fix this, Ive tried including some other headers but I just keep coming up with more errors. #include…
Reaper GM
  • 53
  • 1
  • 7
2
votes
3 answers

Trouble understanding istringstream in C++

I am new to C++ and I was wondering how I can understand what functions and classes do. For example I was told to use "istringstream" for a homework assignment. I have looked online and found the site cplusplus.com with a lot of references. The…