return -1是什么意思啊?

smartpop555 2008-07-29 10:04:55
请问:return -1;是什么意思啊?
...全文
1118 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wjb_yd 2008-07-29
  • 打赏
  • 举报
回复
return -1;
好像代表主函数非正常退出
开心爸爸84 2008-07-29
  • 打赏
  • 举报
回复
1 楼说的对, 个人认为可能你感觉上没什么变化, 这个对于编译器可能是有用的,编译器要知道程序是否安全运行,不过具体,返回-1 编译器会做什么,就不知道了

ps:遇到问题不妨先google 一下, 中文不行,就搜一搜英文的,会有惊喜的
smartpop555 2008-07-29
  • 打赏
  • 举报
回复
这么厉害啊,是primer上的.
但把return -1去了好象也行 啊.
或我改为return 0好象也一样啊.
请指教啊!!谢谢大哥
XiaoG602 2008-07-29
  • 打赏
  • 举报
回复
primer上的是吧,这段程序用来判断是否有标点。
else 
{cout < < "no punctuatinon charactor in the string!" < < endl;
return -1;
};

如果没有标点,return -1,程序结束.
smartpop555 2008-07-29
  • 打赏
  • 举报
回复
是这个程序了
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
string s,result_str;
bool has_punct=false;
char ch;
cout << "enter a string " << endl;
cin>> s;
for(string::size_type index=0;index != s.size();++index)
{
ch=s[index];
if(ispunct(ch))
has_punct =true;
else
result_str += ch;
}
if(has_punct)
cout << "result:" << endl << result_str<< endl;
else
{cout<< "no punctuatinon charactor in the string!" << endl;
return -1;
};
return 0;
}
我把return -1去掉好象也没事 啊!!
开心爸爸84 2008-07-29
  • 打赏
  • 举报
回复
没个上下文,怎么回答你啊
XiaoG602 2008-07-29
  • 打赏
  • 举报
回复
如果是在主函数里的话,一般是程序非成功结束(不算非正常)……

64,654

社区成员

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

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