c++问题error C2440: '=' : cannot convert from 'char *' to 'char'
#include"iostream"#include"string"usingnamespacestd;classSTR{public:STR(char*t){*s=ne...
#include"iostream"
#include"string"
using namespace std;
class STR
{public:
STR(char *t)
{*s=new char[strlen(t)+1];
strcpy(s,t);
m=0,n=0;
}
~STR()
{delete s;}
void fun()
{char *p=s;
int mark=0;
while(*p)
{if(*p=='.')
n++;
if(*p!=' '&&*p!='.'&&*p!=',')
mark=1;
else if(mark==1)
{m++;
mark=0;
}
p++;
}
}
void print()
{cout<<"sentence:"<<n<<"word:"<<m<<endl;}
private:
char *s;
int m,n;
};
void main()
{ char f[200]="I am a student.I am twenty.I come from China.";
//cin.getline(f,20);
STR D(f);
D.fun();
D.print();
}
这是判断一个字符串中的句子数,单词数的程序。编译出现了问题,请大家帮忙。 展开
#include"string"
using namespace std;
class STR
{public:
STR(char *t)
{*s=new char[strlen(t)+1];
strcpy(s,t);
m=0,n=0;
}
~STR()
{delete s;}
void fun()
{char *p=s;
int mark=0;
while(*p)
{if(*p=='.')
n++;
if(*p!=' '&&*p!='.'&&*p!=',')
mark=1;
else if(mark==1)
{m++;
mark=0;
}
p++;
}
}
void print()
{cout<<"sentence:"<<n<<"word:"<<m<<endl;}
private:
char *s;
int m,n;
};
void main()
{ char f[200]="I am a student.I am twenty.I come from China.";
//cin.getline(f,20);
STR D(f);
D.fun();
D.print();
}
这是判断一个字符串中的句子数,单词数的程序。编译出现了问题,请大家帮忙。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询