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

youxia001 2007-04-21 07:00:53
#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),
...全文
240 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
youxia001 2007-04-21
  • 打赏
  • 举报
回复
mymtom() 你好!65行给成 MyString::GetStringByLocation还是报错(这样应该是定义吧)
66行已解决!

用hellox(吃吃饭)方法也不行:
是这样写吗:
Mystring mystring=new Mystring();
char * resultStr= mystring.GetStringByLocation(myStr,0,4);

chenyu2202863 2007-04-21
  • 打赏
  • 举报
回复
String.cpp:65: error: `Mystring' undeclared (first use this function)============〉
你的类名字是MyString,而你写的却是Mystring,当然就说你没声明


cout<<"截取以后的字符串:"<*resultStr;==============〉
这里你写的是'<'而不是用的'<<',当然就没有重载了
hellox 2007-04-21
  • 打赏
  • 举报
回复
MyString.GetStringByLocation(myStr,0,4);
是不行的。。。
LZ是JAVA转C++的吧。。。??看着有点像。。
先建个MyString的对象。。
hellox 2007-04-21
  • 打赏
  • 举报
回复
Mystring.GetStringByLocation(myStr,0,4);//class MyString
cout<<"截取以后的字符串:"<*resultStr;//"<<*resultStr;
mymtom 2007-04-21
  • 打赏
  • 举报
回复
char * resultStr= Mystring.GetStringByLocation(myStr,0,4);//65行
编译错误, 改为
char * resultStr= MyString::GetStringByLocation(myStr,0,4);//65行

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

64,648

社区成员

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

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