Search String

Need checked:

/*
searchString.cpp
*/

#include <iostream>
#include <cstring>

using namespace std;

class Find {

public:

      Find();
      ~Find();
      string findString.num();
      void display();

};

string Find::findString.num() {

      int my_string.find;
      string my_str = "test";
      string target;
      string str;
      int matches = 0;

      int pos = target.find(str);

      while(pos != string::npos) {
            matches ++;
            pos = target.find(str, pos + 1);

      }

}

void display() {

      cout << findString.num() << endl;

}

int main() {

      Find f;
      f.findString.num();
      f.display();

      return 0;

}


edelossantosAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
Well, first of all, dots aren't allowed in method names, 'display()' was missing the class specifier and since you are counting the occurences, you want to return an integer, not a string. Try

/*
searchString.cpp
*/

#include <iostream>
#include <string>

using namespace std;

class Find {

public:

     Find() {};
     ~Find() {};
     int findString_num();
     void display();

};

int Find::findString_num() {

     int my_string_find;
     string my_str = "test";
     string target;
     string str;
     int matches = 0;

     int pos = target.find(str);

     while(pos != string::npos) {
          matches ++;
          pos = target.find(str, pos + 1);

     }

    return matches;

}

void Find::display() {

     cout << findString_num() << endl;

}

int main() {

     Find f;
     f.findString_num();
     f.display();

     return 0;

}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
edelossantosAuthor Commented:
I am getting this:

prob1.cpp:55:2: warning: no newline at end of file

what does this mean?
jkrCommented:
Probably just a problem related to copy&paste from the website into the editor. Just add press 'Enter' at the end of the last line and save, then it should be OK.
edelossantosAuthor Commented:
jkr,

It was an internal compiler .profile issue on my end.  Thanks a million.  Del
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.