Highlight a phrase and click this icon to search it on Swyx-Forum   Highlight a phrase and click this icon to search it within the Swyx Knowledgebase   Highlight a phrase and click this icon to search it using Goolge   Highlight a phrase and click this icon to search it using Wikipedia

 

Highlight a phrase and click this icon to search it on Swyx-Forum   Highlight a phrase and click this icon to search it within the Swyx Knowledgebase   Highlight a phrase and click this icon to search it using Goolge   Highlight a phrase and click this icon to search it using Wikipedia

List of Blogs
Search Blogs
Blog Archive

Most recent blog entries

 

Most recent blog entries

 

Jul17

Written by:Martin
17.07.2009 16:59 

No funny things this time, but something for everybody who knows C++. Somebody (not me) changed this line

if (str.find(‘x’)==0)

to

if (str.find(‘x’)>=0)

This is not made up, but a real code change, a little bit simplified. The intention is to find ‘x' everywhere in the string, not only at the first position. str is a std::string. Why does this change not work as expected?

 

 

Tags:

 

4 comment(s) so far...

Re: Quiz

I would check for != -1 to figure if the string was found, but I can't tell why >= 0 wouldn't work.

By tom.wellige on  18.07.2009 17:36

Re: Quiz

You're right. Your check would work. But I'll wait a little bit to see if someone else finds the solution before I post the answer :-)

By Martin on  20.07.2009 07:53

Re: Quiz

Ok, probably nobody reads this anyway, so I'll no longer wait :-) std::basic_string::find() returns a size_type which is an unsigned int. Therefore every possible value you might get from find() is greater or equal zero. The if statement will never be false, even in the case when 'x' is not found.

By Martin on  21.07.2009 08:54

Re: Quiz

I read it, but had no clue!! ;)

By morten.rokosz on  22.07.2009 20:05

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment  Cancel 
Blog Help
Sponsors
UCIT cloud communication
IPIT Ltd
bluvo AG
logic-base GmbH
Atia Communications

 

 

logic-base GmbH
www.logic-base.de
Atia Communications
www.atiacomms.com
UCIT Nordic
www.ucit.no
IPIT Ltd
www.ipit.co.uk
bluvo AG
www.bluvo.de
logic-base GmbH
www.logic-base.de
Atia Communications
www.atiacomms.com
UCIT Nordic
www.ucit.no
IPIT Ltd
www.ipit.co.uk
bluvo AG
www.bluvo.de