We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Search String

edelossantos
edelossantos asked
on
Medium Priority
239 Views
Last Modified: 2010-04-01
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;

}


Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2012
Commented:
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;

}

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
I am getting this:

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

what does this mean?
jkr
CERTIFIED EXPERT
Top Expert 2012
Commented:
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.

Author

Commented:
jkr,

It was an internal compiler .profile issue on my end.  Thanks a million.  Del
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.