the find member function

This is a discussion on the find member function within the C++ Programming forums, part of the General Programming Boards category; Code: #include < iostream > #include < string > using namespace std; int main() { string greeting = "hello"; cout ...

  1. #1
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357

    the find member function

    Code:
    #include < iostream >
    #include <  string  >
    using namespace std;
    
    int main()
    {
    	string greeting = "hello";
    
    	cout << greeting.find ( 'c', 0 ) << endl;
    
    	return 0;
    }

    Since c isn't in the word hello, shouldn't that cout statement print out -1? Why is it printing out 4294967295?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Failure to find the item results in a return value of string::npos, not -1.
    My best code is written with the delete key.

  3. #3
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357
    Originally posted by Prelude
    Failure to find the item results in a return value of string::npos, not -1.
    What's string::npos? Where did that come from?

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    Originally posted by volk
    What's string::npos? Where did that come from?
    The answer is here

    Oh...and 4294967295 in hex is 0xFFFFFFFF (32 bit int) which is the same as -1.......

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Good example...

    Oh...and 4294967295 in hex is 0xFFFFFFFF (32 bit int) which is the same as -1.......
    A good example of what can happen when you display a signed number as an unsigned int !!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM

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