c++中判断字符串是否为空格的方法:
ifstream infile("xxx.txt",ios::in);
while(!infile.eof()){
infile>>c;
while( (c!=' ') && (c!='\t') && (c!='\n') ){ //这里是过滤字符的核心。
word[pos]=c;
pos++;
infile>>c;
}
word[pos]='\0';
if(pos!=0){
cout<
pos=0;
}
只是判断的话,这样就行了
假设字符串是char str[]
int flag = 0;
for(int i=0;i{
if(str[i]!=' ')
{
flag = 1;
break;
}
}
if(flag)
//是空格
else
//不是
#include
#include
int main()
{
char ch[]="book";
char *p="";
int len1,len2;
len1=strlen(ch);
if(len1!=0)
cout<<" \nnot null.";
else
cout<<"\n is null";
len2=strlen(p);
if(len2!=0)
cout<<"\nnot null.";
else
cout<<"\n is null";
return 0;
}