当前位置: 代码迷 >> C语言 >> 求助
  详细解决方案

求助

热度:343   发布时间:2004-10-07 13:00:00.0
求助

如里我判断字符串中有几个空格,要怎么判断,

是不是这样 s[i]=' ';

望指教!!!!!!!!!!!


----------------解决方案--------------------------------------------------------
if(s[i]==' ')........
----------------解决方案--------------------------------------------------------

'\40'


----------------解决方案--------------------------------------------------------
[原创]

#include<string> #include<iostream> using namespace std;

void main() { int n=0; string str; getline(cin,str); //when input finished, press "Enter" key twice please!!! //here can't be "cin>>str;" because that will only enter one character!!! cout<<str<<endl; for(int i=0;i<str.length();i++) if(str.at(i)=='\40') n++; //str.find('\40'); cout<<n<<endl; }


----------------解决方案--------------------------------------------------------
  相关解决方案