bug in string library?

Discussion in 'C++' started by Randy Yates, Dec 21, 2004.

  1. Randy Yates

    Randy Yates Guest

    The following line of code

    cout << "line.find is " << line.find("County and", 0, 10) << endl;

    prints "line.find is 17." This should never happen since the find should start
    at 0 and go for 10 characters.

    g++ -v
    Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/specs
    Configured with: /gcc/gcc-3.3.3-3/configure --verbose --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-languages=c,ada,c++,d,f77,java,objc,pascal --enable-nls --without-included-gettext --enable-libgcj --with-system-zlib --enable-interpreter --enable-threads=posix --enable-java-gc=boehm --enable-sjlj-exceptions --disable-version-specific-runtime-libs --disable-win32-registry
    Thread model: posix
    gcc version 3.3.3 (cygwin special)
    --
    % Randy Yates % "Though you ride on the wheels of tomorrow,
    %% Fuquay-Varina, NC % you still wander the fields of your
    %%% 919-577-9882 % sorrow."
    %%%% <> % '21st Century Man', *Time*, ELO
    http://home.earthlink.net/~yatescr
     
    Randy Yates, Dec 21, 2004
    #1
    1. Advertising

  2. Randy Yates

    Randy Yates Guest

    Never mind - got it.

    --RY


    Randy Yates <> writes:

    > The following line of code
    >
    > cout << "line.find is " << line.find("County and", 0, 10) << endl;
    >
    > prints "line.find is 17." This should never happen since the find should start
    > at 0 and go for 10 characters.
    >
    > g++ -v
    > Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/specs
    > Configured with: /gcc/gcc-3.3.3-3/configure --verbose --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-languages=c,ada,c++,d,f77,java,objc,pascal --enable-nls --without-included-gettext --enable-libgcj --with-system-zlib --enable-interpreter --enable-threads=posix --enable-java-gc=boehm --enable-sjlj-exceptions --disable-version-specific-runtime-libs --disable-win32-registry
    > Thread model: posix
    > gcc version 3.3.3 (cygwin special)
    > --
    > % Randy Yates % "Though you ride on the wheels of tomorrow,
    > %% Fuquay-Varina, NC % you still wander the fields of your
    > %%% 919-577-9882 % sorrow."
    > %%%% <> % '21st Century Man', *Time*, ELO
    > http://home.earthlink.net/~yatescr


    --
    % Randy Yates % "My Shangri-la has gone away, fading like
    %% Fuquay-Varina, NC % the Beatles on 'Hey Jude'"
    %%% 919-577-9882 %
    %%%% <> % 'Shangri-La', *A New World Record*, ELO
    http://home.earthlink.net/~yatescr
     
    Randy Yates, Dec 21, 2004
    #2
    1. Advertising

  3. Randy Yates wrote:

    > Never mind - got it.


    >>The following line of code
    >>
    >> cout << "line.find is " << line.find("County and", 0, 10) << endl;
    >>
    >>prints "line.find is 17." This should never happen since the find should start
    >>at 0 and go for 10 characters.


    So why did it?

    - J.
     
    Jacek Dziedzic, Dec 21, 2004
    #3
  4. Randy Yates

    Randy Yates Guest

    Jacek Dziedzic <> writes:

    > Randy Yates wrote:
    >
    > > Never mind - got it.

    >
    >
    > >>The following line of code
    > >>
    > >> cout << "line.find is " << line.find("County and", 0, 10) << endl;
    > >>
    > >>prints "line.find is 17." This should never happen since the find should start
    > >> at 0 and go for 10 characters.

    >
    >
    > So why did it?


    I misinterpreted the function, apparently. The
    searchStr.find(char* tokenStr, string::size_type n, string::size_type m) signature of the string
    class's find member function searches searchStr beginning at character n for the first m characters
    of the tokenStr. If m is the length of tokenStr, then this form is identical in function to the
    simpler searchStr.find(char* tokenStr, string::size_type n) form.
    --
    Randy Yates
    Sony Ericsson Mobile Communications
    Research Triangle Park, NC, USA
    , 919-472-1124
     
    Randy Yates, Dec 21, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John

    Re: BUG? OR NOT A BUG?

    John, Sep 20, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    574
  2. RedEye
    Replies:
    2
    Views:
    596
    Jason Kester
    Dec 13, 2005
  3. Michel Joly de Lotbiniere

    Bug Parade Bug 4953793

    Michel Joly de Lotbiniere, Nov 30, 2003, in forum: Java
    Replies:
    4
    Views:
    654
    Michel
    Dec 2, 2003
  4. DarkSpy
    Replies:
    4
    Views:
    899
    tom_usenet
    Jun 27, 2003
  5. Simon Strandgaard

    [bug] String#split returns extra empty string

    Simon Strandgaard, May 31, 2004, in forum: Ruby
    Replies:
    8
    Views:
    349
    David A. Black
    Jun 1, 2004
Loading...

Share This Page