PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > How can I transform source range to destination range that is thesame as source?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How can I transform source range to destination range that is thesame as source?

Réponse
 
LinkBack Outils de la discussion
Vieux 16/07/2008, 12h43   #1
Lambda
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How can I transform source range to destination range that is thesame as source?

I'd like to change all the character in a array to lower case.
I find transform() is convenient.

Because the array is large, I don't want to define another array. I
tried:

transform(buffer, buffer + size, buffer, tolower);

From the output, I find it works.
But when I compile it with Visual C++,
I find a warning that says 'Function call with parameters that may be
unsafe'.

I shouldn't use transform that way?
I must define another array to store the result or
do it without transform?
  Réponse avec citation
Vieux 16/07/2008, 13h11   #2
Sam
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How can I transform source range to destination range that isthe same as source?

Lambda writes:

> I'd like to change all the character in a array to lower case.
> I find transform() is convenient.
>
> Because the array is large, I don't want to define another array. I
> tried:
>
> transform(buffer, buffer + size, buffer, tolower);
>
> From the output, I find it works.
> But when I compile it with Visual C++,
> I find a warning that says 'Function call with parameters that may be
> unsafe'.
>
> I shouldn't use transform that way?


I see nothing wrong with this. The only thing that's wrong here is your
choice of using Microsoft's technology for learning C++. It's a known cause
of brain rot.

> I must define another array to store the result or
> do it without transform?


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEABECAAYFAkh913oACgkQx9p3GYHlUOLHIACeIjNkTD4r38 xxOaJLMLfHazVl
IyAAn3n7voOP+ED3mQTL0ZoMDUoc5/p7
=QuXV
-----END PGP SIGNATURE-----

  Réponse avec citation
Vieux 16/07/2008, 13h20   #3
Michael DOUBEZ
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How can I transform source range to destination range that isthe same as source?

Lambda a écrit :
> I'd like to change all the character in a array to lower case.
> I find transform() is convenient.
>
> Because the array is large, I don't want to define another array. I
> tried:
>
> transform(buffer, buffer + size, buffer, tolower);
>
> From the output, I find it works.
> But when I compile it with Visual C++,
> I find a warning that says 'Function call with parameters that may be
> unsafe'.
>
> I shouldn't use transform that way?


This is a MS feature called check iterator. The compiler warns you that
you may write out of bounds. Are you sure the size is correct ?

> I must define another array to store the result or
> do it without transform?


If you are sure you are right you can silence the compiler by defining:
#define _SECURE_SCL 0

Or using a Windows specific extension:
transform(buffer,buffer+size,
stdext::checked_array_iterator<char*>(buffer, size),
tolower);



--
Michael
  Réponse avec citation
Vieux 16/07/2008, 19h18   #4
James Kanze
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How can I transform source range to destination range that is thesame as source?

On Jul 16, 12:43 pm, Lambda <stephenh...@gmail.com> wrote:
> I'd like to change all the character in a array to lower case.
> I find transform() is convenient.


> Because the array is large, I don't want to define another array. I
> tried:


> transform(buffer, buffer + size, buffer, tolower);


> From the output, I find it works.


Depending on the includes, it's likely to not even compile. And
if it does, the results have undefined behavior.

> But when I compile it with Visual C++,
> I find a warning that says 'Function call with parameters that
> may be unsafe'.


Which one?

> I shouldn't use transform that way?


No.

> I must define another array to store the result or
> do it without transform?


No, but you do have to provide a functional object that is
unambiguous and that works correctly on the data type. You also
should be using std::vector instead of whatever; it would make
life a lot easier.

And finally, of course, you should be aware that upper to lower
case is not necessarily a one to one mapping, and that it is
very locale dependent.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 17h38.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09968 seconds with 12 queries