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

Weird behavior of istringstream object instantiated with a null-terminated character string in C++

I have a null-terminated character string stored in s of type char*. I want to create an istringstream object from s. Since the constructor of istringstream expects a parameter of type string, I need to convert s from char* to string. I did this by…
starforever
  • 107
  • 1
  • 6
2
votes
2 answers

Parse a string to int

I'm pretty new to coding, and I was hoping someone could help me out? I'm trying to read in a line of space delimited integers and parse them into (ultimately into a linked list) a vector. so once i have a vector of ints, there are iterators for…
StillLearningToCode
  • 2,271
  • 4
  • 27
  • 46
2
votes
1 answer

Read lines from istringstream ,without '\r' char at the end

I have a following function : void process (std::string str) { std::istringstream istream(str); std::string line; std::string specialStr("; -------- Special --------------------\r"); // win //std::string specialStr("; --------…
YAKOVM
  • 9,805
  • 31
  • 116
  • 217
1
vote
3 answers

Find how many strings in istringstream

I want to know how many strings there are in my variable when I use istringstream: string cadena; int num; istringstream ss(cadena); ss >> num; int n = ss.size(); // This doesn't work For example if cadena is: "1 2 3 4", when I use istringstream…
EricJ
  • 131
  • 3
  • 13
1
vote
1 answer

sscanf to stringstream conversion

if (1 != sscanf(line, "%s", name)) continue; Earlier in the code we have char line[128]; char name[128]; What's another way of writing this line using istringstream instead of sscanf?
user975900
  • 77
  • 4
  • 11
1
vote
1 answer

cannot extract a double from a case insensitive string?

I am trying to come up with a case insensitive string, and I found the following on the web http://www.gotw.ca/gotw/029.htm So basically my code to come up with a case insensitive string is as follows struct ci_char_traits : public…
aaragon
  • 2,314
  • 4
  • 26
  • 60
1
vote
2 answers

stringstream does not reset across several calls

I'm trying to load in input from a file, representing students. Each student has a name and list of scores, like so: Name John Wayne Scores 100 90 80 100 0 Name Bob Dwight Scores 0 0 10 100 Name Dummy Student Scores 0 0 I am reading this through…
Kevin Li
  • 21
  • 3
1
vote
1 answer

Is it possible to use istringstream to read in more than one parameter of a stream function?

Instead of writing a new istringstream argument, can I add another parameter inside nameStream? I have what I think below, and if this method is elligible, then can I tell the input stream to read in a space or endline to separate the two…
Aquarus
  • 23
  • 4
1
vote
3 answers

How to get two integers separated by space in a char[]?

I will be getting a string of numbers that looks like this. 12 45 Two integers separated with space. The output will be 57. I have tried using, string numbersstream; cin >> numbersstream; istringstram twonumbers (numbersstream); twonumbers >> a >>…
Shane Hsu
  • 7,937
  • 6
  • 39
  • 63
1
vote
1 answer

istringstream skip next (n) word(s)

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; ++i) { std::string tmp; some_stream >>…
Moritz
  • 378
  • 5
  • 14
1
vote
2 answers

Can we create std::istringstream object from a reversed std::string

I am learning C++ using recommended C++ books. In particular, i read about std::istringstream and saw the following example: std::string s("some string"); std::istringstream ss(s); std::string word; while(ss >> word) { std::cout<
Jason
  • 36,170
  • 5
  • 26
  • 60
1
vote
1 answer

C++ Strange Results of String Range Constructor

I have some code similar to this: std::istringstream iss{"SomeChars"}; // Some read ops here (though the problem stays even without them) std::string reconst(iss.str().cbegin(), iss.str().cbegin() + iss.tellg()); std::cout << reconst <<…
Captain Hatteras
  • 490
  • 3
  • 11
1
vote
0 answers

Using istringstream like Scanner in Java

Why doesn't a reference to an object of type istringstream retain its last read character position after passing it to one function after another? I'm trying to use it similar to how a Scanner object in Java works. The goal is to create a function…
Othman H
  • 75
  • 2
  • 9
1
vote
1 answer

How to append string to istringstream?

A websocket server receives messages that need to pass to a function as an std::istream. I am using a istringstream as an intermediate step as: #include #include // std::istringstream, std::stringbuf #include…
neiron21
  • 71
  • 5
1
vote
1 answer

What do istringstreams or stringstreams in general initialize to by default in C++?

I have a class as follows and it has a member of istringstream type. In the constructor for the class what can the istringstream type extracted_text be initialized to? class user_input { std::string input_text; std::istringstream…