"Program received signal SIGSEGV, Segmentation fault."错误

音无八重 2018-05-26 05:09:59
我用的codeblocks,写C++代码调试的时候遇到了这个问题,端点放在了最开始的输出部分,但是刚一打开调试,调试的小箭头就直接指向了Text类里的一个公有方法,这是为什么??烦请有点经验的大大们看一下..
代码如下:
#include <iostream>
#include <string>

using namespace std;
//---------------------------------------------------------------
class Text
{
private:
char S[50];
int length;
int head;
int tail;
int now;
public:
Text();
~Text();
void upDate(); //更新length和tail等数据
void getChar();
char getAChar(int n);
void print();
int getNow();
int getTail();
int getHead();
bool plusNow();
};
Text::Text()
{
for(int i=0;i<50;i++)
this->S[i]='\0';
this->length=0;
this->head=0;
this->tail=0;
this->now=0;
}
Text::~Text(){}
void Text::upDate()
{
int count=0;
while(this->S[count]!='\0')
count++;
this->length=count;
this->tail=this->length;
cout<<"this->length:"<<this->length
<<" this->tail:"<<this->tail<<endl;
}
void Text::getChar()
{
cout<<"cin:";
cin>>this->S;
}
void Text::print()
{
cout<<":"<<this->S<<endl;
}
char Text::getAChar(int n)
{
char c=this->S[n];
return c;
}
int Text::getNow()
{
int n=this->now;
return n;
}
int Text::getTail()
{
return this->tail;
}
int Text::getHead()
{
return this->head;
}
bool Text::plusNow()
{
if(this->now<this->tail)
{
this->now++;
return true;
}
else
return false;
}
int main()
{
Text P,T;
cout<<"T:"<<endl;
T.getChar();
T.upDate();
T.print();
cout<<"P:"<<endl;
T.getChar();
P.upDate();
P.print();

int now,tail;
now=P.getNow();
tail=P.getTail();

return 0;
}
...全文
825 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2018-05-28
  • 打赏
  • 举报
回复
进程意外退出会在当前目录下产生‘core’文件或形如‘core.数字’的文件比如‘core.1234’ 使用命令 gdb 运行程序名 core或core.数字 进入gdb然后使用bt命令 可以查看进程意外退出前函数调用的堆栈,内容为从上到下列出对应从里层到外层的函数调用历史。 如果进程意外退出不产生core文件,参考“ulimit -c core文件最大块大小”命令

64,654

社区成员

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

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