stringstream

Ways std::stringstream can set fail/bad bit?

A common piece of code I use for simple string splitting looks like this: inline std::vector<std::string> split(const std::string &s, char delim) { std::vector<std::string> elems; std::stringstream ss(s); std::string item; while(std::getline(ss, item, delim)) { elems.push_back(item); } return elems; } S...

Problem with istringstream in C++

Hello, I'm sure I'm just doing something stupid here, but I can't quite figure out what it is. When I try to run this code: #include <iostream> #include <string> #include <sstream> using namespace std; int main(int argc, char *argv[]) { string s("hello"); istringstream input(s, istringstream::in); string s2; input >> s2; cou...

Read multiple strings from a file C++

Hi I need to read different values stored in a file one by one. So I was thinking I can use ifstream to open the file, but since the file is set up in such a way that a line might contain three numbers, and the other line one number or two numbers I'm not sure how to read each number one by one. I was thinking of using stringstream but...

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 with my input string stream, but I am not reading the values correctly because only the ...

stringstream problem - vector iterator not dereferencable

Hello I've got a problem with the following code snippet. It is related to the stringstream "stringstream css(cv.back())" bit. If it is commented out the program will run ok. It is really weird, as I keep getting it in some of my programs, but if I just create a console project the code will run fine. In some of my Win32 programs i...

C++ std::stringstream seemingly causes thread to hang or die under SunOS

I have an application developed under Linux with GCC 4.2 which makes quite heavy use of stringstreams to wrap and unwrap data being sent over the wire. (Because the Grid API I'm using demands it). Under Linux everything is fine but when I deploy to SunOS (v5.10 running SPARC) and compile with GCC 3.4.6 the app hangs when it reaches the p...

C++ stringstream reads all zero's

I have a file which contains three integers per line. When I read the line I use a stringstream to separate the values, but it only reads the first value as it is. The other two are read as zero's. ifstream inputstream(filename.c_str()); if( inputstream.is_open() ){ string line; stringstream ss; while( getline(inputstream...

Why was std::strstream deprecated?

I recently discovered that std::strstream has been deprecated in favor of std::stringstream. It's been a while since I've used it, but it did what I needed to do at the time, so was surprise to hear of its deprecation. My question is why was this decision made, and what benefits does std::stringstream provide that are absent from std:...

Can someone explain to me why my output is this? And how would I correct my output?

In this slice of code I get an output of bbb 55 66 77 88 aaa the output I expect and want is bbb 55 66 77 88 bbb because I reassign ss from log[0] to log[1]. So my question is why is the output different from what I expect and how do I change it to what I want? int w,x,y,z; stringstream ss (stringstream::in | stringst...

How do I check if a C++ string is an int?

When I use getline, I would input a bunch of strings or numbers, but I only want the while loop to output the "word" if it is not a number. So is there any way to check if "word" is a number or not? I know I could use atoi() for C-strings but how about for strings of the string class? int main () { stringstream ss (stringstream::in | ...

C++: vector to stringstream

I want to know if it is possible to transform a std::vector to a std::stringstream using generic programming and how can one accomplish such a thing? ...

stringstream was not declared in this scope

I'm having problem with stringstream.my visual studio nor linux g++ can understand stingstream. I've added sstream but it does'nt solve anything. I've worked with it before and really don't know what's up with it now? #include <sstream> #include <stdlib.h> #include "SymbolTable.cpp" #include "setjmp.h" using namespace std; jmp_buf *bfj;...

stringstream issue

I cannot get the following stringstreamm to compile stringstream qss; qss.operator << "some text " ::stringstream.operator << DDateTime::date2Oracle(dFrom) ::stringstream.operator << " more text " ::stringstream.operator << DDateTime::date2Oracle(dUntil); If I just use the << operator without the ::stringstream.operatorit complain...

C++: insert char to a string

Hello, so I am trying to insert the character, which i got from a string, to another string. Here I my actions: 1. I want to use simple: someString.insert(somePosition, myChar); 2. I got an error, because insert requires(in my case) char* or string 3. I am converting char to char* via stringstream: stringstream conversion; char* myC...

Post-Initialize stringstream inside map?

How can I post-initialize an stringstream inside a map? Is it even possible or do I have to create a stringstream*? std::map<std::string, std::stringstream> mapTopics; if(mapTopics.end() == mapTopics.find(Topic)) { mapTopics[Topic] = std::stringstream(""); // Post Initialize <--- } std::map<std::string, std::stringstream>::iterat...

How do I use a class wstringstream variable?

I have a wstring stream that I'm using as sort of a buffer in my class and it is used by a good portion of the methods in this class. However, when I try to do something like this: #include <sstream> class foo { public: void methodA(int x, int y); // Uses mBufferStream void methodB(int x, int y); // Uses mBufferStream pri...

What's the difference between istringstream, ostringstream and stringstream? / Why not use stringstream in every case?

Hello, I think the title says pretty much everything, hehe. I would like you to tell me when to use std::istringstream, std::ostringstream and std::stringstream and why I shouldn't just use std::stringstream in every scenario (like are there any runtime performance issues?). Thanks! PS: I have a third, less important question. Is ther...

Getting a byte value using stringstream

I've got this (incorrect) sample code for getting a value out of stringstream and storing it in a byte-sized variable (it needs to be in a single byte var, not an int): #include <iostream> #include <sstream> using namespace std; int main(int argc, char** argv) { stringstream ss( "1" ); unsigned char c; ss >> c; cout ...

stringstream fails "streaming" negative values in unsigned types?

I'm having same issue in Ubuntu 10.04 using gcc4.4, the same code works fine on RH 5.5 using gcc4.1 #include <sstream> #include <iostream> int main(int argc, char** argv) { std::stringstream myStream; myStream << "-123"; unsigned int myUInt; myStream >> myUInt; if(myStream.fail()) { std::cout << "FAILED" << std::endl; ...

how copy from one stringstream object to another in C++?

I have stringstream object ss1 now I would like to create another copy from this one. I try this std::stringstream ss2 = ss1; or std::stringstream ss2(ss1) neither works The error message is like this std::ios::basic_ios(const std::ios &) is not accessible from bsl::basic_stringstream, bsl::allocator>::basic_stringstream(cons...