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

Read text file into class member variables using getline - c++

I recently started learning c++ so I'm still learning. Basically I'm trying to read my text file when the string "NEW_EMPLOYEE" is found and then store every line into their respective member variables until an empty line is found in the text file…
Anonymous
  • 11
  • 1
  • 5
0
votes
2 answers

Elegant solution to take input to a vector

I am trying to create an vector whose size is not pre-defined. It should take in numbers as long as there are numbers in the input terminal and should stop reading when I hit Enter. I tried many solutions including the ones given here and…
skr
  • 914
  • 3
  • 18
  • 35
0
votes
1 answer

istringstream operator>> return value

Unfortunately this was not helpful... I have a software which throws an exception as implemented, but I need to know how to avoid it. Here is the specific part: if (!(iss >> c)) { throw std::runtime_error( "No return code: status line…
da-chiller
  • 156
  • 1
  • 13
0
votes
2 answers

Why istringstream appends '-1' character at the end of stream?

I've noticed that when I'm using istringstream eof() doesn't return true even if the whole string is "consumed". For example: char ch; istringstream ss{ "0" }; ss >> ch; cout << ss.peek() << " " << (ss.eof() ? "true" : "false"); Outputs(VS2015): -1…
John Lion
  • 5
  • 6
0
votes
1 answer

Using getline and stringstream to check if words in a sentence are in a file

I've been working on an assignment for days and I can't seem to figure this out. I have been given 4 files with words in them (adjectives, nouns, pronouns, and verbs) and I have to check a user inputted sentence and determine the structure of the…
Nick Kinlen
  • 1,356
  • 4
  • 30
  • 58
0
votes
0 answers

istringstream & passing arguments to a function

I'm using a do-while loop to get lines of input from the user via an istringstream. Depending on the input it gets, the program should call the co-responding function. Entering X exits the loop. do { getline(std::cin, input); …
fishyperil
  • 35
  • 6
0
votes
0 answers

Parsing text file and comparing values

Let's say I have a text file in a format like like this... Compton, Calif., 2123, 12 Denver, CO., 3443, 23 Houston, Texas, 3838, 13 Atlanta, GA., 9483, 93 I want to compare the values in the 3rd column and 4th column against each other to check for…
Carai
  • 15
  • 1
  • 5
0
votes
1 answer

Error handling casting to double with stringstream

#include #include #include int main() { std::istringstream iss; iss.str("1.23@45"); double result; iss >> result; std::cout << result << std::endl; if (!iss.eof() || iss.fail()) { std::cout << "error…
triclosan
  • 5,578
  • 6
  • 26
  • 50
0
votes
3 answers

Use stringstream and ifstream to compare user input to words in a file

I am writing a program to compare a user inputted sentence to words in a file. I want the program to tell me if any of the words in the sentence are found in the file. I am using getline to get a user inputted sentence and then I am using a…
Nick Kinlen
  • 1,356
  • 4
  • 30
  • 58
0
votes
1 answer

Program fails to continue when target word is written twice

My source code: #include #include #include #include #include #include #include using namespace std; int main(int argc, char *argv[]){ string target_word=argv[1]; //The…
0
votes
1 answer

Best way to achieve this sort of workflow in C++?

I am doing this problem: https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree/ My approach is to assign serialized string to a stream like "1,#,2,#,#". And then read a character from stream. If it is a '#', return.…
0
votes
1 answer

char not terminating while loop

Okay I have a while loop going on to add chars from one string to a new string and it's supposed to terminate once it reaches a certain character mainly ' ' but instead it continues endlessly. Here's a piece of the program istringstream…
0
votes
0 answers

using istringstream, string to fill to vectors but List2 vector isn't filling, Probably error at iss.str(s); but why?

My code in file.cpp: #include #include #include #include #include #include using namespace std; int main() { ifstream infile("minimum_scalar_product.in"); ofstream…
0
votes
0 answers

C++: Why is compiler reading from istringstream even after it's empty?

I was learning about getline and istringstream and got stuck with this code giving the output "Hello World World" while I was expecting just "Hello World". Can someone tell me why is it printing that and how can it be fixed? Thank you for your help…
0
votes
1 answer

Lvalue istringstream Required for istream_iterator?

Given a string foo in Visual Studio I can break the words into a vector by doing: vector fooVec{ istream_iterator(istringstream(foo)), istream_iterator() }; But this won't compile in gcc 5.1. I get the error: invalid initialization…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288