每人顶了?
if(a==a[dong])出错
error C2676: binary '==' : 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' does not define this operator or a conversion to a type acceptable to the predefin
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
int main(void)
{
string a,beg,max;
cout<<"enter a string:";
cin>>a;
int b=a.length() ;
for(string::size_type i=0;i<b;i++)
{
if(max.length ()<beg.length ())
{
max=beg;
}
else
{
max=max;
}
for(string::size_type dong=i+1;dong<=b;dong++)
{
if(max.length ()<beg.length ())
{
max=beg;
}
else
{
max=max;
}
if(a[i]==a[dong])
{
beg=a[i];
for(string::size_type dan=1;dan<dong-i;dan++)
{
if(a[i+dan]==a[dong+dan])
{
beg+=a[i+dan];
}
else
{
goto begin;
}
}
}
else
{
}
begin:
int o=o+1;
}
}
cout<<max<<'\n';
return 0;
}
不好意思!复制错了!