f53403 2017-04-08 08:31 采纳率: 66.7%
浏览 1086

一道编程,C++,为什么运行不了?统计字符串中字母数字以及其他字符的个数

#include
#include
#include
using namespace std;
int main()
{
string line;
cout<<"please enter a line"<<endl;
getline(cin,line);
string::size_type nLetter=0,nDigit=0,nOthers=0;
for(auto c:line)
{
if(isalpha(c))
++nLetter;
if(isdigit(c))
++nDigit;
else
++nOthers;
}
cout<<"字母有"<<nLetter<<endl;
cout<<"数字有"<<nDigit<<endl;
cout<<"其他字符有"<<nOthers<<endl;
return 0;
}


  • 写回答

1条回答 默认 最新

  • threenewbee 2017-04-08 09:43
    关注

    for(auto c:line)
    这个要支持C++ 11的编译器才能编译

    可以编译运行
    在线验证地址
    http://ideone.com/AaNt6P

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料