当没有输入args时,c++应用程序崩溃
c++ application crashes when no args are entered
我正在创建一个基于命令行的加密软件。我在这里有一个if语句,用于检查是否没有参数,然后用代码1退出。
if (argc = 0) {
errorExit("No arguments listed. Type "-h" for help.", 1);
}
errorExit((在我创建的头文件中。
int errorExit(string errMsg, int errorCode) {
cerr << "Error: ";
cerr << errMsg;
cerr << endl;
exit(errorCode);
return NULL;
}
相反,当我不输入参数时,我的程序会崩溃。
Z:CodeC++CodeBlockssimplecryptbinDebug>simplecrypt.exe
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Z:CodeC++CodeBlockssimplecryptbinDebug>
为了消除混淆,我将代码块与mingw一起使用,以防它是mingw中的一个bug。
编辑:我意识到我有argc=0而不是argc=0。我意识到了错误,但仍然没有解决问题。
主函数可以这样声明:
int main (int argc, char *argv[]);
当您在命令行中调用程序时,argv[0]将是可执行文件的名称,这意味着如果没有其他参数,则argc应为1。
if(argc == 0){...
在if条件中写入==而不是=
相关文章:
- 试图在visual studio上用C++创建一个桌面应用程序
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 在C应用程序中运行C++(带有STL)函数
- 使用VerQueryValue检索应用程序的文件描述
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 使用调试/崩溃报告将应用程序部署到客户端
- C++控制台应用程序阻止退出
- 码头化的C++应用程序是否向后兼容早期的内核版本
- 将应用程序从32位移植到64位时出现问题
- 如何改变c++应用程序的视觉效果
- WM_CTLCOLORSTATIC从未在WIN32应用程序中触发
- PC中的程序和PHONE中的本机描述应用程序之间的数据连接
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 示例外壳应用程序显示的 V8 "segmentation fault (core dumped)"错误
- phytec phyBOARD iMX-6在从闪存而不是SD卡运行qt5 opengles应用程序时表现不佳(FPS减半
- 为什么导入Mixed native/CLR lib.dll的本机C++应用程序没有在Mixed lib.dll中的外部变
- 如何从Windows应用程序输出到标准?
- C++应用程序 MySQL odbc 数据库连接错误:在引发"otl_tmpl_exception<>"实例后终止调用
- 如何在 64 位 vb.net Windows 应用程序中引用 32 位 dll
- 如果整个应用程序是虚拟映射的,为什么 new 会进行系统调用?