[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Search String

Posted on 2006-04-05
4
Medium Priority
?
225 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;

}


0
Comment
Question by:edelossantos
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 16385981
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
 

Author Comment

by:edelossantos
ID: 16386275
I am getting this:

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

what does this mean?
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 2000 total points
ID: 16386321
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
 

Author Comment

by:edelossantos
ID: 16387956
jkr,

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question