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

Detect a newline character with getline or istringstream

In my program, I'm asking the user for input via getline, and then in a separate class, splitting the string into three different strings which I will then check via a list of pre-determined values. The way it works now, if someone enters an invalid…
Alex
  • 2,145
  • 6
  • 36
  • 72
1
vote
1 answer

Way to detect number rather than letter from string. (using istringstream currently)

I made a simple game program, and a requirement calls for a option for the player to undo a number of moves (undo n). I have the user enter in a command (undo n) and it takes the back half and puts it into an int. Basically, I want the program to…
Thomas Brooks
  • 49
  • 1
  • 3
1
vote
1 answer

c++ std::istringstream weird std::hex behaviour

EDIT: I managed to get the same problem on a smaller scale: std::istringstream hex; std::string str = "0x7ffa428ab946"; std::cout << "str " << str << std::endl; hex.str(str); long caller; hex >> std::hex >> caller; std::cout << "caller " << caller…
MoonBun
  • 4,322
  • 3
  • 37
  • 69
1
vote
2 answers

istringstream issue

Problem: I have a text file with lines of information in it as need below under "txt file". I am attempting to map the items so I can finish my assignment. In mapping them I am using istringstream. My problem comes about in getting it to work when…
CBooze
  • 21
  • 5
1
vote
1 answer

passing data from byte array(with zeros) to istringstream(stringstream)

why this code char magicData [] = { 0x00i8, 0xfdi8, 0xffi8, 0xfci8, 0x00i8, 0xf3i8, 0xf4i8, 0xf5i8, 0x00i8}; std::string s; std::istringstream ss(magicData, sizeof(magicData)); while(std::getline(ss, s)) { std::cout << s <<…
sbel
  • 11
  • 3
1
vote
1 answer

istringstream not changing c++

I have written some code to show a problem I am having within another program to convert some input strings . #include #include #include using namespace std; int main() { string tempStr; unsigned…
user2646276
1
vote
1 answer

Dividing in words works incorrectly with zeroes

Recently I've been working on writing snippets for my finals. One of the common task is to divide a string (std::string) into words. In some cases these strings can contain integers. I wrote a snippet: #include #include…
vladfau
  • 1,003
  • 11
  • 22
1
vote
1 answer

Reading in part of an input string with arbitrary number of spaces

I am working on a program that allows a user to add a "department" to school records. The departments are stored as structs like this: struct Department{ string ID; string name; }; To add a new department to the records, the user must enter a…
norman
  • 5,128
  • 13
  • 44
  • 75
1
vote
3 answers

Reading from input streams

I have a programming assignment for a C++ course involving streams and I'm trying to gain a better understanding as to why some of the functions work the way they do. I am reading input from an istringstream with whitespace after the text. Why does…
duffsterlp
  • 347
  • 1
  • 5
  • 15
1
vote
0 answers

Serialization of big objects

I'm working with Boost::Serialization library in C++. When I want to restore the object, I use the code below: // ostr is of type std::ostringstream std::vector newCRL; { std::istringstream ifs(ostr.str()); …
ManiAm
  • 1,759
  • 5
  • 24
  • 43
0
votes
1 answer

Can I treat an isstrstream to obtain random seeks into an underlying i/o buffer?

I have code which will read an entire file into a buffer. For my purposes, I can guarantee that such a file is not over, say, 10MB in size... small enough that we need never concern ourselves with thrashing or real performance issues with doing a…
Mordachai
  • 9,412
  • 6
  • 60
  • 112
0
votes
2 answers

Emulating sscanf's %*s with istreamstream

Possible Duplicate: C++ alternative to sscanf() I have the following line of code sscanf(s, "%*s%d", &d); How would I do this using istringstream? I tried this: istringstream stream(s); (stream >> d); But it is not correct because of *s in…
user975900
  • 77
  • 4
  • 11
0
votes
2 answers

string stream never terminates in while loop

I want to write a generic function to parse CSV files. My code acts very strange as it never stops and repeats the first line forever. What am I doing wrong here? #include #include #include #include…
DEKKER
  • 877
  • 6
  • 19
0
votes
1 answer

The integer token that I need is behind characters so istringstream is not tokenising it

int integers; std::list integersList = {}; string token; while(iss >> token) { if(stringstream(token) >> integers) { integersList.push_back(integers); } } One of the tokens I need to parse is U54778
0
votes
0 answers

Double data type adding changing the digits after decimal point c++

I am inputing some decimal data from a file using ifstream. The double column that I am using changes the decimal values itself. Example if the value in file is 0.714000 it will be changed to 0.71399999999999997. What can I do to keep the value same…
shahmeer arhsad
  • 49
  • 1
  • 2
  • 8