...

View Full Version : C++ Find Function



srule_
10-03-2007, 04:31 PM
When i use the find function does it output an interger value?

EX:



string str1;

str1 = "hello";



So if i had the function in there

cout << str1.find("e");

it would output 1 for the position of the "e" in the string correct? Is this 1 considered an integer and can I use it to compare values?

nikkiH
10-03-2007, 06:56 PM
When you post a question specific to a language, it helps to tell us the version / compiler, if applicable. c++.net has .net classes. This looks like standard from <string.h>...

So, here you go.
http://www.cppreference.com/cppstring/find.html

ralph l mayo
10-03-2007, 08:59 PM
The return type is std::string::size_t. I don't know what portability guarantees you get with that but as far as I've ever determined it's always a typedef of unsigned long. So, yeah, you can use it for regular integer stuff but mind that you don't make comparisons when the result is std::string::npos, which is == ULONG_MAX (also probably implementation-defined, but that's the only sensible value for it if the container is unsigned)

srule_
10-04-2007, 02:58 AM
std::string::size_t.

what the heck does this mean? thee book i'm reading does not mention anything that looks remotly like this :confused:

maybe i should get a new book :p

oracleguy
10-04-2007, 03:48 AM
std::string::size_t.

what the heck does this mean? thee book i'm reading does not mention anything that looks remotly like this :confused:

maybe i should get a new book :p

size_t is a typedef that the string class uses when it returns the length, or positions from find, etc. Your book might just assume it is an int, which can work but most versions of the STL have it mapped to an unsigned long like ralph said.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum