0

I am working on a project where I input a string, and it outputs that string on separate lines of the console. I have got that to work, but my question/error is when I am looking for a specific position of that word. An error message pops up regarding the "unsigned searcher = str.find("good");" with a red underline under "str" saying it needs a class identifier. I have looked online for examples but have no been able to solve this. Please help!

int _tmain(int argc, _TCHAR* argv[])
{
char str[] = "   Hello good sirtttttt..!.";
char * pointer_char;
int pos = 0;
std::string str;
int i = 0;
int length = strlen(str);




string good; // word/char that i want to search

    cin >> good;

for (i = 0; i < length; i++) //i<string size
{
   unsigned searcher = str.find("good");
   if (searcher != string::npos) {
       cout << "found at : " << searcher;
   }

}

1
  • 1
    When asking a question regarding compiler or linker errors, then you should include the actual errors in the question (unedited and complete). You might want to read the Stack Overflow question checklist. Commented Nov 27, 2013 at 18:00

2 Answers 2

4
char str[] = "   Hello good sirtttttt..!.";
...
std::string str;

You have two variables with the same name. Name one differently.

Sign up to request clarification or add additional context in comments.

Comments

1

You have multiple declaration of str.

char str[] = "   Hello good sirtttttt..!.";
char * pointer_char;
int pos = 0;
std::string str;

There is no need to use a char array. Change it to:

//char str[] = "   Hello good sirtttttt..!.";
char * pointer_char;
int pos = 0;
std::string str = "   Hello good sirtttttt..!." ;
int length = str.size();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.