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

use `sscanf` the same as `istringstream`?

Using istringstream, we could read items one by one from a string, for example: istringstream iss("1 2 3 4"); int tmp; while (iss >> tmp) { printf("%d \n", tmp); // output: 1 2 3 4 } could we do this using sscanf?
Alcott
  • 17,905
  • 32
  • 116
  • 173
0
votes
1 answer

C++ problem with string stream istringstream

I am reading a file in the following format 1001 16000 300 12.50 2002 24000 360 10.50 3003 30000 300 9.50 where the items are: loan id, principal, months, interest rate. I'm not sure what it is that I am doing wrong…
user69514
  • 26,935
  • 59
  • 154
  • 188
0
votes
1 answer

splitting a string read from a file/istringstream

I'm currently taking an online C++ class and our current project requires us to read a file, take each student and put it into a vector. My current problem is splitting the name read and setting it to the right variables. The professor's pseudo code…
0
votes
0 answers

Issue with istringstream knowing when reach the end of a line C++

Okay, I've seen answers on here but I still don't understand exactly what I need to do. I am trying to read in stuff from a file but I'm getting unexpected results with .eof() and I'm becoming frustrated with it! I cut out the stuff I'm actually…
Dani
  • 322
  • 2
  • 4
  • 15
0
votes
3 answers

Piping from Istringstream into templates

I have the following questions: I have a map from string to string which is called psMap. I.e. psMap["a"]="20", psMap["b"]="test", psMap["c"]="12.5", psMap["d"]="1" (true) so the map stores string-expressions of various basic-data types. The…
Martin
  • 328
  • 1
  • 6
0
votes
1 answer

C++ : istringstream conversion to long int doesn't work

My problem is, I want to convert a string into a long int. For that, i use an istringstream that way: long x; string lString; istringstream istr; getLine(cin, lString); istr.str(lString); if(!(istr>>x)) return false; //Edited after answer…
user1948708
  • 43
  • 1
  • 2
  • 10
0
votes
2 answers

C++: Cannot open files with stringstream operation

I am editing an existing C++ code such that it opens multiple files using stringsteam. I have a loop with an integer going from 1 to 7, and there are 7 files that I need to open. The files are named PMAP1.txt ... PMAP7.txt. I am trying to open it…
KuroNeko
  • 319
  • 2
  • 8
  • 17
0
votes
2 answers

Storing text file into a class

I am currently trying to read in characters into a class that looks like this struct data { string segment; string name; double length; double radius; double wall_thickness; double young_modulus; double compliance; }; I also have a…
Zavierich
  • 5
  • 1
0
votes
1 answer

istringstream not outputting correct data

I am having trouble getting istringstream to continue in while loop shown below. The data file is shown below also. I use getline from Input file to get the first line and put it in a istringstream lineStream. It passes through the while loop once,…
ddwong
  • 27
  • 1
  • 6
0
votes
1 answer

Getting long long with suffix out of istringstream (C++)

How come istringstream can't seem to fully read numeric literals with suffixes? #include #include using namespace std; int main() { long long x = 123ULL; // shows 123ULL is a valid long long literal istringstream…
ricab
  • 2,697
  • 4
  • 23
  • 28
0
votes
2 answers

Why is this returning an address in the console?

I'm trying to wrap my head around ostringstreams and istringstreams. So, as I always do, I made a log-in program out of it. but every time I try to cout the contents of the username and password variables, it returns the address! Purpose for…
0
votes
0 answers

strtok vs istringsteam on splitting the strings?

I am trying to split my actual key on dot and then extract all the fields after splitting it on dot. My key would look like something this - t26.example.1136580077.colox Below is the code I have which I was in the impression, it should work fine…
AKIWEB
  • 19,008
  • 67
  • 180
  • 294
0
votes
1 answer

Infinite loop with file handling and istringstreams

I have a file containing data in the following form: ballcolor 10 bgcolor 5 [...] Which I'm trying to read via the following: void read (const char *filename) { ifstream prefsfile (filename); if (prefsfile.is_open ()) { char…
user2064000
0
votes
1 answer

Why am i getting the error "segmentation fault" when i run the program?

I am attempting to read in a file (input.txt) and go string by string and storing only the words in a vector (name). this is a part of a bigger project however I am stuck here. The program compiles however when i go to run it i get the error…
Trenton
  • 13
  • 4
0
votes
2 answers

C++ : istringstream looping twice

I'm currently working on a mock process scheduler. The code reads a text file of fake processes, and I need to be able to parse through the file. Text file is formatted as shown below. Pid Bst Arr Pri Dline I/O 1 1 850 …