Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Couting number of substring occurances in C++
#include<iostream> #include<string> #include<algorithm> using namespace std; int countFreq(string str, string str_to_search) { int count = 0, nPos = str.find(str_to_search, 0); // fist occurrence while (nPos != string::npos) { count++; nPos = str.find(str_to_search, nPos + 1); } cout << count; } int main() { int chars; cin >> chars; string filename, finder; cin >> filename >> finder; countFreq(filename, finder); return 0; }
run
|
edit
|
history
|
help
0
BubDoubLinArray
Tree
pointconcat
congruence modulo equations (together with a simple BigInteger class)
typedef
PrintShapePointer
Hi
cppPyClassInit
VecScalMultiOpLaod
Precendence of Pointer Indirection Example