Of course, you could have s[I]+32 or s[I]-32
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
using namespace std;
int main()
{
string s = "Hello World";
cout << s << endl;
transform(s.begin(),s.end(),s.begin(),::toupper);//<span style="font-family:'Times New Roman';">::toupper</span>to<span style="font-family:'Times New Roman';">upp<span style="font-family:'Times New Roman';">er</span></span>
cout << s << endl;
transform(s.begin(),s.end(),s.begin(),::tolower);//<font face="'Times New Roman'">::t<span style="font-family:'Times New Roman';">olo<span style="font-family:'Times New Roman';">wer<span style="font-family:'Times New Roman';">使用</span></span></span></font><span style="font-family:'Times New Roman';"></span>to<span style="font-family:'Times New Roman';">lower</span>
cout << s << endl;
return 0;
}
Toupper and tolower are defined in C++ in STD and cctype, respectively
When defined in STD, the prototype is charT Toupper (charT C, Const Locale& loc);
While the transform function:
Applies an operation to each element of the specified scope.
The Transform function has two overloaded versions:
transform(first,last,result,op); // First is the first iterator of the container, last is the last iterator of the container, result is the container that holds the result, op is the unary function object or STURct, class to be operated on.
transform(first1,last1,first2,result,binary_op); // First1 is the first iterator of the first container, last1 is the last iterator of the first container, first2 is the first iterator of the second container, result is the container that holds the result, and binary_OP is the binary function object or STURct, class to be operated on
As above, the STD of toupper prototype as a binary function, so the use of STD: : toupper complains: unresolved overloaded function
But you can use it this way:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string s = "Hello World";
cout << s << endl;
transform(s.begin(),s.end(),s.begin(),(int (*)(int))toupper);
cout << s << endl;
transform(s.begin(),s.end(),s.begin(),(int (*)(int))tolower);
cout << s << endl;
return 0;
}
Function pointer resolves
Read More:
- Java callback function implementation case
- Explicit and implicit conversion of Java data type
- Code case of XXL job executor
- [Solved] JAVA fx Error: java.lang.instrument ASSERTION FAILED ***: “!errorOutstanding“ with message transform
- Asynchronous callback case of Java callback function
- The problem of date format conversion between springboot and front end
- mybatis “case when” Error: Failed to process, please exclude the tableName or statementId.
- Conversion of two data types in Java
- [Solved] In case of “transactionmanager” while setting bean property “transactionmanager” error
- [Solved] Mapreducer Class Conversion error: java.lang.ClassCastException
- [Solved] WebFlux Error: DataBufferLimitException: Part headers exceeded the memory usage limit of 8192 bytes
- How to convert a Java string into a number (stringtonumber)
- C++: Implementation of multi-channel IO transfer with select
- [Solved] Java Run Error: For input string: “XXX”
- The principle and return value of get() function in C language
- Problems and causes of Java’s main function format (public static void main (string args()))
- JAVA: How to Delete the Last Bit of String
- Idea error: (44,22) Java: constant string too long
- Tensorflow Error TypeError: Fetch argument XXXX has invalid typeXXXX,must be a string or Tensor
- [Solved] Swagger Startup Error: java.lang.NumberFormatException: For input string: ““