Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   stringstream delimiter (http://www.programmingforums.org/showthread.php?t=12257)

quantalfred Dec 26th, 2006 12:42 AM

stringstream delimiter
 
Is it possible to change the delimiter of a stringstream? For example,
:

#include<sstream>
#include<string>

int main(){
std::string s;
std::stringstream ss("A B C");
ss >> s;
}


Then s is "A". Is it possible to make s be "A B C"?

Wizard1988 Dec 26th, 2006 12:46 AM

http://www.cprogramming.com/faq/cgi-...&id=1044780608

quantalfred Dec 26th, 2006 1:12 AM

Thanks, I know I can do it other way. But I still want to know whether I can do it within stringstream or not.

Eoin Dec 26th, 2006 7:20 AM

Well the following will work:
:

#include<sstream>
#include<string>

int main(){
std::string s;
std::stringstream ss("A B C");
s = ss.str();
}

Is that want you're looking for?

Wizard1988 Dec 26th, 2006 1:38 PM

No he is looking for a way to split "A-B-C" or "A:B:C" using string streams.

Eoin Dec 26th, 2006 2:25 PM

Not sure if that is what he wants, the post is very unclear.

Any-hoo this link might be useful: skipws / noskipws

quantalfred Dec 26th, 2006 3:50 PM

Quote:

Originally Posted by Eoin (Post 121738)
Well the following will work:
:

#include<sstream>
#include<string>

int main(){
std::string s;
std::stringstream ss("A B C");
s = ss.str();
}

Is that want you're looking for?

No, I want to see if there is a way to do something like getline(x,y,delim) using the operator >>. It's something like std::skipws but std::skipws is only about the first white space but not the delimiter.

After some googling and searching in my books, it seems that there is no way to do it just by using the operator >> . Anyone could confirm this?

quantalfred Dec 26th, 2006 3:53 PM

Quote:

Originally Posted by Eoin (Post 121750)
Not sure if that is what he wants, the post is very unclear.

Any-hoo this link might be useful: skipws / noskipws

Yeah, I now see why it was unclear as I should write "A B C \n" instead. So instead of stopping at the first white space, is it possible to change the stream to make it stop at \n.

Jimbo Dec 26th, 2006 4:21 PM

I think stringstream extends iostream, so you should be able to use the getline function, which allows you to set a delimiter.


All times are GMT -5. The time now is 1:27 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC