#include<iostream.h> //头文件,用到cout和cin要有。
#include<fstream.h> //头文件,用到fin和fout要有。
#include <time.h> //头文件,用到clock()时要有。
#include<math.h> // 头文件,用到数学函数时要有。
#include<stdlib.h> // 头文件,用函数malloc,realloc,free时要有。
#include<string> //头文件,用到exit()时要有.
typedef struct{
char *ch;
int length;
}hstring;
int strlength(hstring s,hstring t,hstring r)
{
return s.length;
return t.length;
return r.length;
}
int strcompare(hstring s,hstring t)
{
int i;
for(i=0;i<s.length&&i<t.length;++i)
if(s.ch[i]!=t.ch[i])
return s.ch[i]-t.ch[i];
return s.length-t.length;
}
int substring(hstring sub,hstring s, int pos ,int len,hstring t)
{
int i;
len=t.length;
if(pos<1 || pos>s.length || len<0 || len>s.length-pos+1)
return 0;
if(sub.ch)
free(sub.ch);
else{
sub.ch=(char *)malloc(len *sizeof(char));
for(i=0;i<=len-1;++i)
sub.ch[i]=s.ch[pos-1+i];
sub.length=len;
}
return 1;
}
int index(hstring s,hstring t,int pos,hstring &sub)
{
int n,m,i;
if(pos>0)
{
n=s.length;m=t.length;i=pos;
while(i<=n-m+1)
{
substring(sub,s,i,m,t);
if(strcompare(sub,t)!=0)
++i;
else return i;
}
}
return 0;
}
int strinsert(hstring &s,int pos, hstring t,hstring &sub)
{
ofstream fout("output.txt",ios::out);
int i;
index(s,t,pos,sub);
i=index(s,t,pos,sub);
if(pos<1 || pos>s.length+1)
return 0;
if(t.length)
{
if(!(s.ch=(char *)realloc(s.ch,(s.length+t.length)*sizeof(char))))
exit(0);
for(i=s.length-1;i>=pos-1;--i)
s.ch[i+t.length]=s.ch[i];
for(i=0;i<=t.length-1;++i)
s.ch[i+pos-1]=t.ch[i];
s.length+=t.length;
fout<<"the sum is:"<<s.length<<endl;
for(i=0;i<=s.length;i++)
fout<<"the string is:"<<s.ch[i]<<endl;
fout.close();
}
return 1;
}
void main()
{
ifstream fin("input.txt",ios::in); //定义fin和fout.
if(!fin)
cout<<"can't open file "<<endl;
ofstream fout("output.txt",ios::out);
int *s,*t,*r,l,m,n,h,pos,*sub;
fin>>m>>n>>h;
s=new int[m];
t=new int[n];
r=new int[h];
for(l=0;l<m;++l)
fin>>s[l];
for(l=0;l<n;++l)
fin>>t[l];
for(l=0;l<h;++l)
fin>>r[l];
strinsert(s, pos,t,sub);
fin.close();
fout.close();
}
错: error C2664: 'strinsert' : cannot convert parameter 1 from 'int *' to 'hstring &'
A reference that is not to 'const' cannot be bound to a non-lvalue
Error executing cl.exe.
.exe - 1 error(s), 0 warning(s)