search for text

This is a discussion on search for text within the C++ Programming forums, part of the General Programming Boards category; hey all, can some one throw me a bone and tell me why this cant find the word cin? the ...

  1. #1
    Village id10t
    Join Date
    May 2008
    Posts
    57

    search for text

    hey all,

    can some one throw me a bone and tell me why this cant find the word cin? the rest of the program tests ok, so the mistake is with my logic

    Code:
    for(counter=0;counter<text.size();counter++)
    {
     if(text[counter]=='c' && text[counter+1]=='i' && text[counter+2]=='n')
      {
      cout<<"cin found!";
      }
        counter++;
                            
    }

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    You're doing counter++ twice.

    On a related note, your way to find a matching substring seems a little lame.

  3. #3
    Village id10t
    Join Date
    May 2008
    Posts
    57
    of course it is lame, I have 2 weeks experience, any suggestions?

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 06:20 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  3. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21