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
1 answer

std::bad_cast when using std::basic_istringstream

I'm trying to process UTF-16 string (placed in a buffer buf) with the help of std::basic_string and istringstream. An exception std::bad_cast occurs in this code. Is there a problem with my code? Or gcc's STL just cannot handle unsigned int (16 bit)…
Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335
0
votes
1 answer

Strange behaviour using std::istringstream with '>>' operator

I've noticed a strange behaviour with the very simple program just below. #include #include #include int main(void) { std::string data = "o BoxModel\nv 1.0f, 1.0f, 1.0f\nv 2.0f, 2.0f, 2.0f\n"; …
user1364743
  • 5,283
  • 6
  • 51
  • 90
0
votes
2 answers

Splitting string by spaces difficulty

My code is working except for one problem, when I run it it doesn't seem to return the first string. string text; cin >> text; getline(cin ,text); istringstream iss(text); copy(istream_iterator(iss), …
user2757849
  • 227
  • 3
  • 4
  • 14
0
votes
5 answers

c++ istringstream() function converting string to int raises error

I have a string of digits. I am trying to print it as an int type each single digit in the string using istringstream. It works fine if pass whole string as argument to conversion function in main but if I pass it by index, it raises error. How to…
enterprize
  • 1,179
  • 8
  • 29
  • 43
0
votes
0 answers

istringstream extraction operatror fails

I'm working on a very simple parser for wavefront *.obj files. The general idea is to read each line of the file and then based on the start keyword parse that line accordingly, but I have some troubles with it: bool Model::loadModel(const char*…
user1274605
  • 405
  • 2
  • 6
  • 17
0
votes
3 answers

(C++) std::istringstream reads up to 6 digits from string to double

folks! I've been struggling with this problem for some time and so far I haven't found any solution to it. In the code below I initialize a string with a number. Then I use std::istringstream to load the test string content into a double. Then I…
Santus Westil
  • 43
  • 1
  • 5
0
votes
1 answer

Stream types in C++, how to read from IstringStream?

i have a txt file that has millions of lines, each line has 3 floats, i read it using the following code : ifstream file(path) float x,y,z; while(!file.eof()) file >> x >> y >> z; and i works perfectly. Now i want to try doing the same thing…
OopsUser
  • 4,642
  • 7
  • 46
  • 71
0
votes
1 answer

C++ - can't move istringstream definition out of loop

I have the following piece of code: #include #include using namespace std; int main() { string inp, s; istringstream iss; do { getline (cin, inp); iss(inp); int a = 0, b = 0; float c =…
user2064000
0
votes
2 answers

How to do parsing istringstream C++?

I need to print some data from stream - istringstream ( in main () ). example: void Add ( istream & is ) { string name; string surname; int data; while ( //something ) { // Here I need parse stream cout <<…
user1779502
  • 573
  • 2
  • 8
  • 16
0
votes
2 answers

istringstream invalid error beginner

I have this piece of code : if(flag == 0) { // converting string value to integer istringstream(temp) >> value ; value = (int) value ; // value is a } I am not sure if I am using the istringstream operator right . I want to convert the variable…
thestralFeather7
  • 529
  • 2
  • 10
  • 28
0
votes
2 answers

C++ stringstream to char* conversion memory allocation

Can anyone explain how the following code is working and does not crash the application? int main() { char *tempStr = new char[5]; tempStr[0] = '\0'; string stemp = "helloworld"; stringstream sstream; sstream.str(stemp); cout…
N3Xg3N
  • 97
  • 1
  • 12
0
votes
1 answer

sscanf to istringstream confusion c++

I want to convert the following C code to C++ utilizing istringstream: void test(char *s) { int i; sscanf(s, "%*s%d", &i); } What I have so far is: void test(char *s) { int i; istringstream iss(s); iss >> s >> i; } It comes up with…
0
votes
2 answers

istringstream() (possibly) memory leak

Suppose you want to read the data from large text file (~300mb) to array of vectors: vector *Data (assume that the number of columns is known). //file is opened with ifstream; initial value of s is set up, etc... Data = new…
Oleg Shirokikh
  • 3,447
  • 4
  • 33
  • 61
0
votes
2 answers

wordwap function fix to preserve whitespace between words

Some time ago I was looking for a snippet to do a wordwrap for a certain size of line length without breaking up the words. It was working fair enough, but now when I started using it in edit control, I noticed it eats up multiple white space…
Ulterior
  • 2,786
  • 3
  • 30
  • 58
0
votes
5 answers

istringstream rounds long numbers - how can I prevent that ?

Given the following code : istringstream i("2.11099999999999999999"); double d; if (!(i >> d)) {d = 0;} cout << d << endl; The output is 2.111 . I want to have the ability of working with long numbers , float numbers (floating point included) ,…
JAN
  • 21,236
  • 66
  • 181
  • 318