Thread: Bizarre behavior of the string::find() function

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Streams have a void* conversion operator.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Programmer_P
    What void* conversion function?
    Something like:
    Code:
    operator void*() const;
    In the next version of the C++ standard library we expect it to become:
    Code:
    explicit operator bool() const;
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #18
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by Elysia View Post
    Streams have a void* conversion operator.
    That I assume gets implicitly invoked automatically behind the scenes?
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, because void* is a pointer and is thus boolean testable.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by Elysia View Post
    Yes, because void* is a pointer and is thus boolean testable.
    Ok, thanks. I'll definitely employ that approach in future programs then. I see no reason to switch ReplaceStrsInLines to use that approach now, as the other one seems to work just fine.

    Quote Originally Posted by Programmer_P View Post
    This function has worked ok up until today, after which I'm getting weird unexpected results. Basically, the string::find() function is returning string::npos when its not supposed to (i.e. when each search string IS contained inside buffer_str), thereby causing an instance of 'std:ut_of_range' to be thrown from string::replace().
    Ok, nevermind. I realized what's breaking it, and that is that my function does not expect for one search string to be part of another search string. Since I was passing the search strings "C_html_element" and "_element", it broke my function.

    Alright, I guess I'll have to avoid using such use cases then, or find a way to make the function work with it.
    Last edited by Programmer_P; 03-09-2011 at 11:40 AM.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 04:25 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM