可能是中毒了吧 请高手指点

flower243 2008-11-09 06:44:24
我用的是studio2005 下面代码调试后说是:系统找不到指定文件!
下面是编译器说我有的错误:(后面 还有源代码

1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(25) : error C2143: syntax error : missing ';' before '&'
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(25) : error C2433: 'ostream' : 'friend' not permitted on data declarations
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(25) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(25) : error C2061: syntax error : identifier 'ostream'
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(25) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(25) : error C2805: binary 'operator <<' has too few parameters
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(26) : error C2143: syntax error : missing ';' before '&'
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(26) : error C2433: 'istream' : 'friend' not permitted on data declarations
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(26) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(26) : error C2061: syntax error : identifier 'istream'
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(26) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(26) : error C2805: binary 'operator >>' has too few parameters
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(41) : error C3861: 'strlen': identifier not found
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(44) : error C3861: 'strcpy': identifier not found
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(51) : error C2146: syntax error : missing ';' before identifier 'str'
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(72) : error C3861: 'strlen': identifier not found
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(77) : error C2065: 'cout' : undeclared identifier
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(77) : error C2065: 'endl' : undeclared identifier
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(91) : error C2065: 'lenth' : undeclared identifier
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(160) : error C3861: 'strlen': identifier not found
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(168) : error C3861: 'strcpy': identifier not found
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(172) : error C2143: syntax error : missing ';' before '&'
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(172) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(172) : error C2086: 'int ostream' : redefinition
1> c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(25) : see declaration of 'ostream'
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(172) : error C2065: 'ostr' : undeclared identifier
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(172) : error C2065: 's' : undeclared identifier
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(172) : error C2275: 'String' : illegal use of this type as an expression
1> c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(4) : see declaration of 'String'
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(172) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\josun\desktop\thirdwork\thirdwork\stringseq.h(172) : fatal error C1903: unable to recover from previous error(s); stopping compilation
1>生成日志保存在“file://c:\Users\josun\Desktop\Thirdwork\Thirdwork\Debug\BuildLog.htm”
1>Thirdwork - 29 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========
...全文
95 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
muyingchi 2008-11-10
  • 打赏
  • 举报
回复
什么头文件都没引啊,iostream的还有一些stdio的,那些错误是说没有找到类型,例如istream,ostream,原因就是你没引头文件
「已注销」 2008-11-10
  • 打赏
  • 举报
回复
厚道点,分数分了结贴吧,你闯入"敌"营了

哈哈
cursor_wang 2008-11-09
  • 打赏
  • 举报
回复
你这个是C++的.这里是JAVA区.搞错了.
flower243 2008-11-09
  • 打赏
  • 举报
回复
头文件:
class String
{
private:
char *str; //串
int size; //当前长度
int maxSize; //最大长度
void GetNext(const String& t,int next[])const;
int KMPFind(const String& t,int start,int next[])const;
public:
String(char *s=""); //
String(int max); //
String(const String &s); //

~String(void);
void Insert(int pos,char *t);
void Delete(int pos,int length);
String Substr(int pos,int length);

char& operator[](int n);
String& operator= (const String& s);
String& operator= (char *s); //操作符=的两个重载

friend ostream & operator<<(ostream & ostr,const String & s);
friend istream& operator>>(istream& istr,String& s);
int operator==(char *s)const;
int operator==(const String&s)const;
friend int operator==(char* strL,const String& strR);


int FindSubstr(const String&t,int start)const;

int FindSubstr(const String&t,int start,int m)const;

};


String::String(char *s)
{
size=strlen(s);
maxSize=size+1;
str=new char[maxSize];
strcpy(str,s); //C++的串拷贝函数调用
}

String::String(int max)
{
maxSize=size;
size=0
str=new char[maxSize];
}

String::String(const String &s)
{
maxSize=s.maxSize;
size=s.size;
str=new char[maxSize];

for(int i=0;i<maxSize;i++)
str[i]=s.str[i];
}

String::~String(void)
{
delete []str;
}


void String::Insert(int pos, char *t) //插入
{
int length=strlen(t);
int i;

if(pos>size||pos<0)
{
cout<<"插入参数位置出错"<<endl;
return;
}

if(size+length>=maxSize-1)
{
char*p=str;
str=new char[size+length+1];
for(i=0;i<=size;i++)
str[i]=p[i];
delete []p;
}

for(i=size;i>=pos;i--)
str[i+lenth]=str[i];

for(i=0;i<length;i++)
str[pos+i]=t[i];

maxSize=size+length+1;
size=size+length;
}

void String::Delete(int pos, int length) //删除
{
int charsLeft=size-pos;

if(pos>size-1)return;

if(length>charsLeft) length=charsLeft;


for(int i=pos;i<=size;i++)
str[i]=str[i+length];

size=size-length;
}


String String::Substr(int pos, int length)
{
int charsLeft=size-pos;
String temp;

if(pos>size-1)return temp; //返回空串

if(length>charsLeft)length=charsLeft;

delete []temp.str;
temp.str=new char[length+1];

for(int i=0;i<length;i++)temp[i]=str[i+pos];


temp[length]=NULL;
temp.size=length;
temp.maxSize=length+1;

return temp;
}


char& String::operator[](int i)
{
return str[i];
}

String& String::operator=(const String& s)
{
if(maxSize<s.maxSize){
delete []str;
str=new char[s.maxSize];
}
size=s.size;
maxSize=s.maxSize;
for(int i=0;i<=size;i++){
str[i]=s.str[i];
}
return *this;
}

String& String::operator =(char *s)
{
int length=strlen(s);
if(maxSize<length+1)
{
delete[] str;
str=new char[length+1];
maxSize=length+1;
}
size=length;
strcpy(str,s);
return *this;
}

ostream& operator<<(ostream& ostr, String& s)
{
cout<<"s.size="<<s.size<<endl;
cout<<"s.maxSize="<<s.maxSize<<endl;
cout<<"s.str"<<s.str<<endl;

return ostr;
}


istream& operator>>(istream&istr ,String& s)
{
delete []s.str;
cout<<"输入字符串的个数: ";
cin>>s.size;
s.maxSize=s.size+1;
s.str=new char[s.maxSize];

cout<<"输入字符串:";
for(int i=0;i<s.size;i++)
cin>>s.str[i];
s.str[s.size]=NULL;

return istr;
}



int String::operator ==(const String &s) const
{
return(strcmp(str,s.str)==0);
}

int String::operator==(char *s)const;
{
return(strcmp(str,s)==0);
}

int operator==(char *strL,const String& strR) //strL是字符串,strR是类名
{
return(strcmp(strL,strR.str)==0);
}


//按Brute-Force算法思想设计的模式函数
int String::FindSubstr(const String &t, int start) const //查找从start开始的子串t
{
int i=start,j=0,v;
int count=0;
while(i<size&&j<t.size)
{
if(str[i]==t.str[j])
{
i++;
j++;
}
else
{
i=i-j+1;
j=0;
}
count++
}
if(j==t.size){v=i-t.size;
cout<<"Brute-Force比较次数:"<<count<<endl;}
else {v=-1;
cout<<"Brute-Force比较次数: 0,"<<endl;}

return v;
}


int String::KMPFind(const String &t, int start, int next[]) const
{
int i=start,j=0,v;
int count=0;

while(i<size&&j<t.size)
{
if(str[i]==t.str[j])
{
i++;
j++;
}
else if(j==0)i++;
else j=next[j];
count++;
}

if(j==t.size)
{
v=i-t.size;
cout<<"KMP比较次数:"<<count<<endl;
}
else
{
v=-1;
cout<<"KMP比较次数:0,"<<endl;
}

return v;

}


void String::GetNext(const String &t, int next[]) const
{
int j=1,k=0;
next[0]=-1;
next[1]=0;
while(j<t.size-1)
{
if(t.str[j]==t.str[k])
{
next[j+1]=k+1;
j++;
k++;
}
else if(k==0)
{
next[j+1]=0;
j++;
}
else k=next[k];
}
}

int String::KMPFindSubstr(const String& t,int start)const
{
int m=t.size;
int *next=new int[m];
GetNext(t,next);
int v=KMPFind(t,start,next);
delete []next;

return v;
}

cpp代码:
#include"stdafx.h"
#include"StringSeq.h"
#include<string.h>

#include <iostream.h>


#include<stdlib.h>


void main(void)
{
String s=("cddcdc"),t=("abcde");
int i=s.FindSubstr(t,0);
cout<<"第"<<i<<"个字母相同"<<endl;
int i=s.KMPFindSubstr(t,0);
cout<<"第"<<i<<"个字母相同"<<endl;

}

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧