LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-24-2004, 03:26 AM   #1
nyk
Member
 
Registered: Jan 2004
Location: Berne, Switzerland
Distribution: FC4, Gentoo
Posts: 112

Rep: Reputation: 15
C++ STL count() number of substring occurences...


I want to use the STL function
Code:
occur=string.count(string2,0)
to find out how many times the (shorter) string string2 occurs in string. I found the count function in an STL tutorial, but the compiler says: `count' undeclared!
Is there an other name for this function that can be used with the GNU C++ ?
or are there some special includes needed? I already have these:
Code:
#include <iostream>
#include <map>
#include <string>
 
Old 06-24-2004, 04:40 AM   #2
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
<algorithm>
 
Old 06-25-2004, 04:32 AM   #3
nyk
Member
 
Registered: Jan 2004
Location: Berne, Switzerland
Distribution: FC4, Gentoo
Posts: 112

Original Poster
Rep: Reputation: 15
thanx!
I already tried #include <algorithm> but z=k.count(ik) still doesnt work... (z=int, k,ik=string)
Still produces the error: `count' undeclared.

Now I just use this code to count the stuff myself:

Code:
z=ik.find(k);o=0;
while (z!=-1) {z=ik.find(k,z+k.size());o++;}
then the int o has the number of occurences... a bit more complicated, but it works...
 
Old 06-25-2004, 05:53 AM   #4
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
Oops - my fault. string doesn't have a member function count.
I thought you were talking about std::count and didn't read your post thoroughly.

A good STL reference can be found http://www.sgi.com/tech/stl/stl_index_cat.html

Or I recommend this book http://www.josuttis.com/libbook/

Last edited by dakensta; 06-25-2004 at 05:56 AM.
 
Old 06-25-2004, 07:12 AM   #5
nyk
Member
 
Registered: Jan 2004
Location: Berne, Switzerland
Distribution: FC4, Gentoo
Posts: 112

Original Poster
Rep: Reputation: 15
thanks again, a good refererence sure will be usefull!
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
count total number of lines in several files xushi Programming 5 11-12-2005 04:42 PM
Javasript to count number of mouse clicks LinuxLala Programming 3 06-17-2005 12:23 AM
How to count number of argument received by a script? philipina Linux - General 2 07-05-2004 02:35 AM
Count number of line in a file. philipina Programming 7 03-18-2004 05:04 PM
Vim editor, right hand bottom number count jules_fraser Linux - Newbie 15 12-06-2003 06:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration