PDA

View Full Version : index of a string that appears n times



deepikha
18th October 2017, 15:03
hello i am able to get index of "@" in c++ but not in qt. i dont know what i have to use to find("@",found+1,q)

#include <iostream> // std::cout
#include <string> // std::string

int main ()
{
std::string str ("msel@-txt/l<seq_name>@#ifndef I_MSEL_@-txt/u<seq_name>@_H");
std::string tag ("@");



// different member versions of find in the same order as above:
std::size_t found = str.find(tag);
if (found!=std::string::npos)
std::cout << "first '@' found at: " << found << '\n';

for (int i = 0; i <= 5; i++)
{ int q =1;
found=str.find("@",found+1,q);
q++;
if (found!=std::string::npos)
std::cout << " '@' found at: " << found << '\n';
}

return 0;
}

high_flyer
22nd October 2017, 22:33
but not in qt
Show the Qt code.