-
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.
-
I think it might return NULL if the value is not found. Not sure though. Try it and see what happens.
-
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.
-
THANK YOU golfnguy4:D :D :D