Is this standard c++ behaviour or a bug? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 183
Joined: Mon Jan 28, 2019 8:22 am

Is this standard c++ behaviour or a bug?

Post by Wolfgang »

Code: Select all

if (befehl.find(" ") > 0)
	{
This gets executed if found and also if not found!
}

Code: Select all

wxInt16 testm = befehl.find(" ");
	if (testm > 0)
	{
	This only gets executed when found!
	}
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: Is this standard c++ behaviour or a bug?

Post by PB »

unlike wxString::Find(), wxString::find() is same as as std::string::find(), it returns size_t, i.e., an unsigned integer.

If find() does not find the string, std::string::npos is returned so you have to check for this value
http://www.cplusplus.com/reference/string/string/find/
Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 183
Joined: Mon Jan 28, 2019 8:22 am

Re: Is this standard c++ behaviour or a bug?

Post by Wolfgang »

PB wrote: Fri Mar 08, 2019 6:42 am unlike wxString::Find(), wxString::find() is same as as std::string::find(), it returns size_t, i.e., an unsigned integer.

If find() does not find the string, std::string::npos is returned so you have to check for this value
http://www.cplusplus.com/reference/string/string/find/
Thanks, now I understand the difference is wxString::Find() to wxString::find().
Post Reply