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?
 
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;

}
0
 
edelossantosAuthor Commented:
I am getting this:

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

what does this mean?
0
 
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.
0
 
edelossantosAuthor Commented:
jkr,

It was an internal compiler .profile issue on my end.  Thanks a million.  Del
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.