VCv6.0 and stl::string 
Author Message
 VCv6.0 and stl::string

Which is what the for() expresion is for, since it separates the
initialization, test, and increment operations out neatly for you:

for (pos = strSource.find(strFind, pos); pos != -1; pos =
strSource.find(strFind,pos))
{
    // ...

Quote:
}

----

Can anybod offer me a reasonable explanation as to why compilers *still*
don't complain to high heaven when as programmers we do something as
error-prone as:

if (pos = f(x) != -1)

?????????

Assignment durring a test should be a warning, if not out right illegal.



Sat, 28 Apr 2001 03:00:00 GMT  
 VCv6.0 and stl::string
Most compilers don't complain about

if ((x = f(x)) != 0)

because the explicit comparison supposedly implies that the programmers know
what they're doing (comparing the result of the assigment with something).

Something without the comparison, e.g.,

if (x = f(x))   /* note '=', not '==' */

generally is flagged as a warning because it's often a typo.  The first
other case (with the comparison) is generally not a typo (although you can
certainly argue that it's hard to read).

-- KDJ

Quote:

>Which is what the for() expresion is for, since it separates the
>initialization, test, and increment operations out neatly for you:

>for (pos = strSource.find(strFind, pos); pos != -1; pos =
>strSource.find(strFind,pos))
>{
>    // ...
>}

>----

>Can anybod offer me a reasonable explanation as to why compilers *still*
>don't complain to high heaven when as programmers we do something as
>error-prone as:

>if (pos = f(x) != -1)

>?????????

>Assignment durring a test should be a warning, if not out right illegal.



Sat, 28 Apr 2001 03:00:00 GMT  
 VCv6.0 and stl::string
On Tue, 10 Nov 1998 16:54:41 -0500, "Steven S. Wolf"

Quote:

>Can anybod offer me a reasonable explanation as to why compilers *still*
>don't complain to high heaven when as programmers we do something as
>error-prone as:

>if (pos = f(x) != -1)

VC does, and has since version 1 IIRC.  You just need to turn the
warning level up to 4 (and add about 500 #pragma disables to avoid all
the warnings from the standard headers).

In the MS compiler, it should really be a W3 warning, IMHO.  

--
 David Foster            |  "But I've been to the pointless forest,  

 finger for PGP key      |              -- Oblio, The Point



Sun, 29 Apr 2001 03:00:00 GMT  
 VCv6.0 and stl::string
Quote:

>Hi all

>Does find() and replace() work in VC ver6.0 for stl string?

>Maybe I am doing something wrong. Can somebody pls send me some sample code?

>#include <string>
>#include <iostream>
>#include <iomanip.h>

                  ^^

Should this be

#include <iomanip>



Mon, 30 Apr 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Warnings using STL Map<string,string>

2. VARIANT String assign to STL string

3. Does the STL string support unicode strings?

4. STL string and const_cast

5. Bug in .net string/stl

6. STL String problem in VC7

7. STL strings and .NET

8. BSTR , CSTring and STL string

9. STL map<string, IHTMLElement*> Elements

10. stl string to CComBSTR

11. How to convert an STL string to uppercase

12. putting a stl list item into a string

 

 
Powered by phpBB® Forum Software