我试图了解如何使用std::tolower
...
#include <iostream>
#include <string>
#include <algorithm>
#include <locale>
int main()
{
std::string test = "Hello World";
std::locale loc;
for (auto &c : test)
{
c = std::tolower(c, loc);
}
std::transform(test.begin(), test.end(), test.begin(), ::tolower); // 1) OK
std::transform(test.begin(), test.end(), test.begin(), std::tolower); // 2) Cryptic compile error
std::transform(test.begin(), test.end(), test.begin(), static_cast<int(*)(int)>(std::tolower)); // 3) Cryptic compile error. Seems OK with other compilers though
return 0;
}
所以:
- 为什么
::tolower
版本有效? - 为什么
std::tolower
不能在 std::transform 中工作? static_cast<int(*)(int)>(std::tolower))
真正想要做什么?为什么它适用于 GCC 而不适用于 Visual Studio 2013?- 那么我如何
std::lower
在 std::transform 中使用 Visual Studio 2013 呢?