|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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----- |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|