The constant npos

This is a discussion on The constant npos within the C++ Programming forums, part of the General Programming Boards category; I was playing with some of the string functions and the VS help says that rfind returns npos if it ...

  1. #1
    Registered User WebSnozz's Avatar
    Join Date
    Oct 2001
    Posts
    102

    The constant npos

    I was playing with some of the string functions and the VS help says that rfind returns npos if it doesn't find the string I'm searching for in the string I'm searching in. I thought npos was some sort of enumerated type or something. But I get an error and I tried to do it like they show the examples. Anyone help me please?

    PHP Code:
    #include <string>
    #include <iostream>

    using namespace std;

    int main()
    {
        
    cout<<"enter a word";
        
    string astring;
        
    cin>>astring;
        if(!(
    astring.rfind("A")==npos))
        {
            
    //do whatever if it finds the letter
        
    }
        return 
    0;

    --------------------Configuration: STRNG - Win32 Debug--------------------
    Compiling...
    main.cpp
    C:\Program Files\Microsoft Visual Studio\MyProjects\AddIns\Strng\main.cpp(11) : error C2065: 'npos' : undeclared identifier
    Error executing cl.exe.
    WebSnozz-
    Cats have no butt cheeks.
    If one farted, then it would make a flute noise.

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    I think it might return NULL if the value is not found. Not sure though. Try it and see what happens.

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    I just realized what you were talking about. npos is the Number POSition of the characters. If it doesn't find it, it will not return a position. Hence, NULL as I already said.

  4. #4
    Registered User WebSnozz's Avatar
    Join Date
    Oct 2001
    Posts
    102
    THANK YOU golfnguy4

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. Try out my new game :) !
    By Stan100 in forum Game Programming
    Replies: 10
    Last Post: 06-05-2003, 09:10 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM

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