Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > bug in string library?

Reply
Thread Tools

bug in string library?

 
 
Randy Yates
Guest
Posts: n/a
 
      12-21-2004
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."
%%%% <(E-Mail Removed)> % '21st Century Man', *Time*, ELO
http://home.earthlink.net/~yatescr
 
Reply With Quote
 
 
 
 
Randy Yates
Guest
Posts: n/a
 
      12-21-2004
Never mind - got it.

--RY


Randy Yates <(E-Mail Removed)> 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."
> %%%% <(E-Mail Removed)> % '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 %
%%%% <(E-Mail Removed)> % 'Shangri-La', *A New World Record*, ELO
http://home.earthlink.net/~yatescr
 
Reply With Quote
 
 
 
 
Jacek Dziedzic
Guest
Posts: n/a
 
      12-21-2004
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.
 
Reply With Quote
 
Randy Yates
Guest
Posts: n/a
 
      12-21-2004
Jacek Dziedzic <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed), 919-472-1124
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
*bug* *bug* *bug* David Raleigh Arnold Firefox 12 04-02-2007 03:13 AM
String[] files = {"a.doc, b.doc"}; VERSUS String[] files = new String[] {"a.doc, b.doc"}; Matt Java 3 09-17-2004 10:28 PM
[bug] String#split returns extra empty string Simon Strandgaard Ruby 8 06-01-2004 01:52 PM
String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 3 12-05-2003 04:20 PM
Re: String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 0 12-04-2003 04:40 PM



Advertisments