C++新手空指针问题求助

淡定从容我自繁华 2012-07-05 10:26:27

#include <iostream>
#include <vector>
#include <string>
using namespace std;
int iFunBellRadioAnalyzeAlarm(string sOrgReportBuff);
vector<string> CutString(string source,string separator);
int main(){
string str = "abc;def;ghi;";
int t = iFunBellRadioAnalyzeAlarm(str);
cout<<"t"<<t<<endl;
}
int iFunBellRadioAnalyzeAlarm(string sOrgReportBuff){
string separator=";";
vector<string> result=CutString(sOrgReportBuff,separator);
string alarmobject = result[1];
cout<<"alarmobject:"<<alarmobject<<endl;
sOrgReportBuff.erase(result[0].length()+1,result[1].length()+1);
cout<<"sOrgReportBuff:"<<sOrgReportBuff<<endl;
return 0;
}

vector<string> CutString(string source,string separator)
{
vector<string> result;
string cut;
int pos=source.find(separator);
while(pos!=-1)
{
cut=source.substr(0,pos);
source=source.substr(pos+separator.length());
pos=source.find(separator);
result.push_back(cut);
}
result.push_back(source);
return result;
}

大家好,上面这段代码是一个程序中的一部分,我根据那一部分改成上面这个文件。因为程序经常core掉,所以我想请问下大家是不是因为上面这个字符串处理导致的问题,谢谢大家了
...全文
142 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2012-07-05
  • 打赏
  • 举报
回复
进程意外退出会在当前目录下产生形如‘core.数字’的文件比如‘core.1234’
使用命令
gdb 运行程序名 core.数字
进入gdb然后使用bt命令
可以查看进程意外退出前函数调用的堆栈,内容为从上到下列出对应从里层到外层的函数调用历史。
Jadenmai 2012-07-05
  • 打赏
  • 举报
回复
我看到的有可能出现coredump地方有一个,就是
string alarmobject = result[1];
result如果长度没有大于等于2,这句话会coredump。
  • 打赏
  • 举报
回复
core掉是程序产生异常导致程序崩溃,产生core文件。现在估计是空指针导致的,但是不知道是不是上面这段代码的原因导致的
Jadenmai 2012-07-05
  • 打赏
  • 举报
回复
core掉是什么意思啊?
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
进程意外退出会在当前目录下产生形如‘core.数字’的文件比如‘core.1234’
使用命令
gdb 运行程序名 core.数字
进入gdb然后使用bt命令
可以查看进程意外退出前函数调用的堆栈,内容为从上到下列出对应从里层到外层的函数调用历史。
[/Quote]你好,按照你那个gdb命令,情况如下:
gdb BellRadio_History core1207051318927196
GNU gdb 6.0
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "sparc-sun-solaris2.8"...总线错误 ((主存储器)信息转储)
1、这种情况是我命令使用错了吗?
2、我直接用gbd core1207051318927196 进入gdb后使用bt命令,结果:No stack.
请您再解答一下好吗?不胜感激

64,654

社区成员

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

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