Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 26th, 2006, 12:42 AM   #1
quantalfred
Newbie
 
Join Date: Jan 2005
Posts: 21
Rep Power: 0 quantalfred is on a distinguished road
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"?
quantalfred is offline   Reply With Quote
Old Dec 26th, 2006, 12:46 AM   #2
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 422
Rep Power: 4 Wizard1988 is on a distinguished road
http://www.cprogramming.com/faq/cgi-...&id=1044780608
__________________

Wizard1988 is offline   Reply With Quote
Old Dec 26th, 2006, 1:12 AM   #3
quantalfred
Newbie
 
Join Date: Jan 2005
Posts: 21
Rep Power: 0 quantalfred is on a distinguished road
Thanks, I know I can do it other way. But I still want to know whether I can do it within stringstream or not.
quantalfred is offline   Reply With Quote
Old Dec 26th, 2006, 7:20 AM   #4
Eoin
Hobbyist Programmer
 
Eoin's Avatar
 
Join Date: Jun 2006
Location: Ireland
Posts: 152
Rep Power: 3 Eoin is on a distinguished road
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?
__________________
Visit my website BinaryNotions.
Eoin is offline   Reply With Quote
Old Dec 26th, 2006, 1:38 PM   #5
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 422
Rep Power: 4 Wizard1988 is on a distinguished road
No he is looking for a way to split "A-B-C" or "A:B:C" using string streams.
__________________

Wizard1988 is offline   Reply With Quote
Old Dec 26th, 2006, 2:25 PM   #6
Eoin
Hobbyist Programmer
 
Eoin's Avatar
 
Join Date: Jun 2006
Location: Ireland
Posts: 152
Rep Power: 3 Eoin is on a distinguished road
Not sure if that is what he wants, the post is very unclear.

Any-hoo this link might be useful: skipws / noskipws
__________________
Visit my website BinaryNotions.
Eoin is offline   Reply With Quote
Old Dec 26th, 2006, 3:50 PM   #7
quantalfred
Newbie
 
Join Date: Jan 2005
Posts: 21
Rep Power: 0 quantalfred is on a distinguished road
Quote:
Originally Posted by Eoin View Post
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 is offline   Reply With Quote
Old Dec 26th, 2006, 3:53 PM   #8
quantalfred
Newbie
 
Join Date: Jan 2005
Posts: 21
Rep Power: 0 quantalfred is on a distinguished road
Quote:
Originally Posted by Eoin View Post
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.
quantalfred is offline   Reply With Quote
Old Dec 26th, 2006, 4:21 PM   #9
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 769
Rep Power: 3 Jimbo is on a distinguished road
I think stringstream extends iostream, so you should be able to use the getline function, which allows you to set a delimiter.
__________________
<insert disclaimer here>
<insert shameless plug for Visual Studio here>
Jimbo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unicode & ANSI support w/ string & stringstream Cache C++ 0 May 9th, 2006 7:34 PM
stringstream expects a space at the end of input? InfoGeek C++ 5 Apr 29th, 2006 8:46 AM
Remove last char from a stringstream yOURsELF C++ 10 Mar 24th, 2006 6:23 PM
stringstream Ancient Dragon C++ 12 Jun 3rd, 2005 5:50 PM
Delimiter Fun Supadude Java 5 Jan 17th, 2005 12:41 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:57 AM.

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