The most recentProgramK-means-based text clustering, as the starting ship of C ++ learning. Found hisCodeUnable to run. And there are errors in the code. So I will make corrections here.
Code
# Include < Iostream >
# Include < Vector >
# Include < Algorithm >
# Include < String >
# Include < Cmath >
# Include < Locale >
Using Namespace STD;
Bool Myfunction ( String S1, String S2)
{
If (S1.compare (S2 ))
{
Return True ;
}
Return False ;
}
String Mytolower ( String SRC)
{
Locale LOC;
String Result = "" ;
For (Size_t I = 0 ; I < SRC. Length (); ++ I)
{
// Cout <tolower (SRC [I], Loc );
Result. append ( 1 , Tolower (SRC [I], Loc ));
}
Return Result;
}
Int Main ()
{
String S1 = " Donkey. testtest \ n in a circle " ;
String S2 = " Donkey. testtest2 \ n in a circle " ;
Vector < String > Strvec;
Vector < String > : Iterator it;
Strvec. push_back (S1 );
Strvec. push_back (S1 );
Strvec. push_back (S2 );
Strvec. push_back (S2 );
Cout < " Before transform operation " < Endl;
For ( Int I = 0 ; I < Strvec. Size (); I ++ )
{
Cout < Strvec [I] < Endl;
}
Transform (strvec. Begin (), strvec. End (), strvec. Begin (), mytolower );
Cout < " Before unique operation " < Endl;
For ( Int I = 0 ; I < Strvec. Size (); I ++ )
{
Cout < Strvec [I] < Endl;
}
It = Unique (strvec. Begin (), strvec. End (), myfunction );
Strvec. Resize (it - Strvec. Begin ());
Cout < " After unique operation " < Endl;
For ( Int I = 0 ; I < Strvec. Size (); I ++ )
{
Cout < Strvec [I] < Endl;
}
Int End;
Scanf ( " % D " , & End );
Return 0 ;
}