鱼C论坛

 找回密码
 立即注册
查看: 1315|回复: 1

[已解决]c++使用cctype的isupper报错

[复制链接]
发表于 2022-1-21 18:18:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. #include <iostream>
  2. #include <cctype>
  3. #include <algorithm>
  4. #include <iterator>
  5. #include <vector>
  6. using namespace std;

  7. int main()
  8. {
  9.     char cList[10] = {'a', 'i', 'C', 'd', 'e',
  10.                       'f', 'o', 'H', 'u', 'j'};
  11.     vector<char> charList(cList, cList + 10);
  12.     vector<char>::iterator position;
  13.     position = find_if(charList.begin(), charList.end(), isupper);
  14.     return 0;
  15. }
复制代码

报错.png
最佳答案
2022-1-21 19:22:09
你为什么要禁用C++的名字空间?
C++为什么要引入名字空间?是为了解决什么问题?

  1. $ cat main.cpp
  2. #include <algorithm>
  3. #include <cctype>
  4. #include <iostream>
  5. #include <iterator>
  6. #include <vector>

  7. int main() {
  8.     char cList[10] = {'a', 'i', 'C', 'd', 'e', 'f', 'o', 'H', 'u', 'j'};
  9.     std::vector<char> charList(cList, cList + 10);
  10.     std::vector<char>::iterator position;
  11.     position = find_if(charList.begin(), charList.end(), isupper);
  12.     std::cout << position - charList.begin() << std::endl;
  13.     return 0;
  14. }
  15. $ g++-debug -o main main.cpp
  16. $ ./main
  17. 2
  18. $
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-1-21 19:22:09 | 显示全部楼层    本楼为最佳答案   
你为什么要禁用C++的名字空间?
C++为什么要引入名字空间?是为了解决什么问题?

  1. $ cat main.cpp
  2. #include <algorithm>
  3. #include <cctype>
  4. #include <iostream>
  5. #include <iterator>
  6. #include <vector>

  7. int main() {
  8.     char cList[10] = {'a', 'i', 'C', 'd', 'e', 'f', 'o', 'H', 'u', 'j'};
  9.     std::vector<char> charList(cList, cList + 10);
  10.     std::vector<char>::iterator position;
  11.     position = find_if(charList.begin(), charList.end(), isupper);
  12.     std::cout << position - charList.begin() << std::endl;
  13.     return 0;
  14. }
  15. $ g++-debug -o main main.cpp
  16. $ ./main
  17. 2
  18. $
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-25 01:40

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表