In my project i have to iterate over a large string starting from index=0 and get length k substring. I've implemented string::substr() and wonder if there are other efficient methods.
For example :
std::string S ="ABCDEFGHIJKLMN"
i need to get all substrings of length =5 starting from the beginning of S.Just like
"ABCDE", "BCDEF", "CDEFG" and so on..
My implementation is like below:
void geekfunc(std::string &str)
{
unsigned int index=0;
for (; index<=(str.size()-K);++index)
{
++myseqmap[str.substr(index,K)];
}
}
This function is being called ten million times and I welcome other methods to try.
kof your input string?