Bizarre behavior of the string::find() function

This is a discussion on Bizarre behavior of the string::find() function within the C++ Programming forums, part of the General Programming Boards category; Streams have a void* conversion operator....

  1. #16
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    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
    21,794
    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;
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    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 10:40 AM.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

Page 2 of 2 FirstFirst 12
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, 03: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, 06: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21