求助
如里我判断字符串中有几个空格,要怎么判断,
是不是这样 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; }
----------------解决方案--------------------------------------------------------