注册 登录
编程论坛 C++教室

达不到语气效果@

未未来 发布于 2013-02-27 18:08, 267 次点击
程序代码:
#include<iostream>
#include<string>
#include<cctype>
using namespace::std;
    int main(){
        string st;
    cout<<"Enter some string"<<endl;
    cin>>st;
    int a,b,c,d;
    for(string::size_type ix=0;ix!=st.size();++ix){
        if(isalpha(st[ix])){
        ++a;}
        if(isdigit(st[ix])){
        ++b;    }
        if(isspace(st[ix])){
            ++c;    }
        if(ispunct(st[ix])){
            ++d;    }
    }

cout<<a<<endl;
cout<<b<<endl;
cout<<c<<endl;
cout<<d<<endl;
return 0;
}



这是用来统计字符的吗,
当输入 “  a 1,” 时达不到预期的效果,
请人指教哪里错了。
2 回复
#2
fanpengpeng2013-02-27 20:10
int a,b,c,d;
需要初始化为0
#3
未未来2013-02-27 21:43
回复 2楼 fanpengpeng
嗯 问题解决了。。。。。谢谢
1