473,805 Members | 2,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

split string contain special token?

Hi, all:
I want to implement a function (using std::string and std::vector)
split a string contain special token into vector.
eg:
string = "alex delia john"

==>

vector[0] = "alex";
vector[1] = "delia";
vector[2] = "john";

I want use some stl algorithms library function,but I don't kown which
algorithms function is suitable.
Thanks !
Alex 2005.01.12

Jul 22 '05
15 6798
> I don't get it quite. Especially this part:

(std::istream_i terator<std::st ring>(iss)),
std::istream_it erator<std::str ing>());


The first is an iterator to read strings from the input stream iss. The
second is what I'd call an EOF-iterator -- when the first iterator
reaches the end of the input stream, it will compare equal to the
second iterator.

--
Later,
Jerry.

The universe is a figment of its own imagination.

Jul 22 '05 #11
Default User wrote:
Peter Koch Larsen wrote:
The best thing would be to give your workmates a boost using boost.
Here you get well-documented, tested code. Much better than anything
you can expect yourself to deliver.

I see this a lot, but I'll point out that many real projects don't
allow the programmers to drag in whatever third-party libraries they
feel like. It would take a long period of evaluation (as the Boost
stuff is non-standard and not provided by a vendor you can go to to
complain).
Even if you can't use the Boost Libraries for some bureaucratic reason, you
still may be able to copy the implementation of a useful algorithm, or
reimplement the algorithm based on the boost design and informed by its
implementation.
Brian


Jonathan
Jul 22 '05 #12

"Jerry Coffin" <jc*****@taeus. com> wrote in message
news:11******** *************@c 13g2000cwb.goog legroups.com...
I don't get it quite. Especially this part:

(std::istream_i terator<std::st ring>(iss)),
std::istream_it erator<std::str ing>());


The first is an iterator to read strings from the input stream iss. The
second is what I'd call an EOF-iterator --


From 14882:

istream_iterato r();

1 Effects: Constructs the end*-of-*stream iterator.

Now you know what to call it. :-)
The details, for anyone interested:

24.5.1 Template class istream_iterato r

1 istream_iterato r reads (using operator>>) successive elements
from the input stream for which it was constructed. After it
is constructed, and every time ++ is used, the iterator reads
and stores a value of T. If the end of stream is reached
( operator void*() on the stream returns false), the iterator
becomes equal to the end*-of-*stream iterator value. The constructor
with no arguments istream_iterato r() always constructs an end of
stream input iterator object, which is the only legitimate iterator
to be used for the end condition. The result of operator* on an end
of stream is not defined. For any other iterator value a const T&
is returned. The result of operator*-> on an end of stream is not
defined. For any other iterator value a const T* is returned. It
is impossible to store things into istream iterators. The main
peculiarity of the istream iterators is the fact that ++ operators
are not equality preserving, that is, i == j does not guarantee at
all that ++i == ++j. Every time ++ is used a new value is read.

2 The practical consequence of this fact is that istream iterators
can be used only for one*-pass algorithms, which actually makes
perfect sense, since for multi-pass algorithms it is always more
appropriate to use in*-memory data structures.

3 Two end*-of*-stream iterators are always equal. An end*-of*-stream
iterator is not equal to a non-*end*-of-*stream iterator. Two non*-
end*-of-*stream iterators are equal when they are constructed from
the same stream.
-Mike
Jul 22 '05 #13
On 12 Jan 2005 19:48:22 -0800 in comp.lang.c++, ze*******@gmail .com wrote,
I want to implement a function (using std::string and std::vector)
split a string contain special token into vector.
eg:
string = "alex delia john"


http://groups.google.com/gr*********....earthlink.net

Jul 22 '05 #14
> istream_iterato r();

1 Effects: Constructs the end*-of-*stream iterator.

Now you know what to call it. :-)


I guess so. If nothing else, this is proof that (contrary to popular
belief) I'm _not_ the most verbose person on earth! :-)

--
Later,
Jerry.

The universe is a figment of its own imagination.

Jul 22 '05 #15
Jonathan Turkanis wrote:
Default User wrote:
[Boost]
I see this a lot, but I'll point out that many real projects don't
allow the programmers to drag in whatever third-party libraries they feel like.

Even if you can't use the Boost Libraries for some bureaucratic reason, you still may be able to copy the implementation of a useful algorithm, or reimplement the algorithm based on the boost design and informed by its implementation.

That's true, depending on how much one Boost element relies on others
(I haven't looked into the implementations very deeply). I also don't
know what the licensing issues are, and of course this isn't really the
forum to discuss them.


Brian

Jul 22 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
12241
by: Andy Mee | last post by:
Hello one and all, I'm developing an Asp.NET system to take a CSV file uploaded via the web, parse it, and insert the values into an SQL database. My sticking point comes when I try to split() the string returned by readline() on the file. The following code snippet works for me: tokens = "one,two,three,four".Split(",") for each token in tokens response.write("<td>"+token+"</td>")
4
649
by: indranil b | last post by:
void tokenise(const string& data, const string& separator, vector<string>& fields) { size_t n = data.length(); size_t start = data.find_first_not_of(separator); while (start < n) { size_t stop = data.find_first_of(separator, start); if (stop > n) stop = n; fields.push_back(data.substr(start, stop-start)); start = data.find_first_not_of(separator, stop+1);
5
57205
by: Vamsi | last post by:
Hi, I am trying a basic opearation of splitting a multiline value to an array of single lines(Actually making Address into AddressLine1, AddressLine2). I used Environment.NewLine in split, I could get only 1st line, but it is not returning 2nd line. here's code: string address = null; string ssep = Environment.NewLine; char sep = ssep.ToCharArray();
4
3387
by: dchan1 | last post by:
String line = " I am new to c# "; How to use Regex to split the string so that It would return a String array with: token = "I" token = "am" token = "new" token = "to" token = "c#"
22
2941
by: Sven-Thorsten Fahrbach | last post by:
Hi Does anybody know of a library that offers a function to split pathnames. It should work somewhat like the following code snippet: ----------------- char *path = "/home/user/Documents/Textdocuments/Bills"; char **dirs; splitPath(path, dirs);
15
6006
by: nagar | last post by:
I need to split a string whenever a separator string is present (lets sey #Key(val) where val is a variable) and rejoin it in the proper order after doing some processing. Is there a way to use the Regex.Split function to split the string whenever the #Key(val) occurrs but that keeps the #Key(val) occurrences to that I can reconstruct the final string after doing certain operations on each token (I need to basically convert each string...
10
2521
by: teddyber | last post by:
Hello, first i'm a newbie to python (but i searched the Internet i swear). i'm looking for some way to split up a string into a list of pairs 'key=value'. This code should be able to handle this particular example string : qop="auth,auth-int,auth-conf",cipher="rc4-40,rc4-56,rc4,des, 3des",maxbuf=1024,charset=utf-8,algorithm=md5-sess
6
1869
by: giffy | last post by:
HOW to get the spaces out of a delimited string ?? here is a usage scenario where split() seems not to work String origAVNListStr = "~`L~`L~`L~`~`~`L~`"; String strArr = origAVNListStr.split("~`"); for(int i=0;i<strArr.length;i++) { System.out.println(i+1 +"the next token - " + strArr); } and the output is
5
1523
mickey0
by: mickey0 | last post by:
hello, I have to read a text and I decided to split it with Scanner class. private Vector<String> splitWords(Scanner s) { Vector<String> v = new Vector<String>(); while ( s.hasNext() ) { String token = s.next(); if ( token.length() == 1 && (token == "." || token == ";" || token == "," || token == ":") ) { continue;
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10613
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10368
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10107
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3846
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.