首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

初学C++,几个Dev编译异常,请各路高手指正!谢谢

2012-02-16 
初学C++,几个Dev编译错误,请各路高手指正!多谢!#includeiostreamusingnamespacestdclassMyString{publi

初学C++,几个Dev编译错误,请各路高手指正!多谢!
#include   <iostream>

using   namespace   std;  

class   MyString
{
        public:
       
        static   char   *   GetStringByLocation(char   *   srcStr,int   startL,int   endL)
        {
                //if(startL <endL   ||   startL <0)
                //{
                //   return   null;      
                ///}        
                int   i=0;
                char   *   resultStr=new   char[endL-startL+1];
                while(*srcStr!= '\0 ')
                {
                        if(i> =startL   &&   i <=endL)
                        {
                                *resultStr++=*srcStr++;
                        }  
                        else
                        {
                                srcStr++;
                        }                              
                        i++;  
                }    
                return   resultStr;          
        }          
        static   void   StrCmp(char   *   toStr,   char   *   fromStr)
        {
                int   strLength=GetStrLength(fromStr);
                toStr=new   char[strLength];
                while(*fromStr!= '\0 ')
                {
                      *toStr++=*fromStr++;                          
                }                    
        }          
        static   char   *ConvertStr(char   *   str)
        {
                  int   strLength=GetStrLength(str);


                  char   *   convert=new   char[strLength];
                  for(int   i=0;i <strLength;i++)
                  {
                          *convert++=*(str+(--strLength));
                  }  
                  return   convert;  
        }        
        static   int   GetStrLength(char   *   str)
        {
                int   i=0;
                while(str!= '\0 ')
                {
                        str++;
                        i++;
                }
                return   i;                
        }      
};

int   main()
{      
        char   *   myStr= "Hello   World! ";
        char   *   resultStr=   Mystring.GetStringByLocation(myStr,0,4);//65行
        cout < < "截取以后的字符串: " <*resultStr;
        cin.get();
        //return   0;
}    
 
编译错误如下:
String.cpp:   In   function   `int   main() ':
String.cpp:65:   error:   `Mystring '   undeclared   (first   use   this   function)
String.cpp:65:   error:   (Each   undeclared   identifier   is   reported   only   once   for   each   function   it   appears  
String.cpp:66:   error:   no   match   for   'operator < '   in   'std::operator < <(std::basic_ostream <char,   _Traits> &,   const   char*)   [with   _Traits   =   std::char_traits <char> ]((&std::cout),

[解决办法]
char * resultStr= Mystring.GetStringByLocation(myStr,0,4);//65行
编译错误, 改为
char * resultStr= MyString::GetStringByLocation(myStr,0,4);//65行

cout < < "截取以后的字符串: " <*resultStr; // 66 行
改为
cout < < "截取以后的字符串: " < < resultStr;

[解决办法]
String.cpp:65: error: `Mystring ' undeclared (first use this function)============〉
你的类名字是MyString,而你写的却是Mystring,当然就说你没声明


cout < < "截取以后的字符串: " <*resultStr;==============〉
这里你写的是 ' < '而不是用的 ' < < ',当然就没有重载了

热点排行