尝试获取命令行参数的核心转储.(C++)
Core Dump with trying to take command line arguments. (C++)
我一直在尝试C++命令行参数,遇到了一些问题。最初,我试图使用"=="运算符将"argv"与字符串进行比较。我很快就明白了,比较的是指针,而不是数值。我修复了那个错误,但现在我在运行时得到了这个错误。
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid
Aborted (core dumped)
这个程序编译得很好,我也没有收到编译器的警告。这是我的源代码,这样你就可以帮我找到问题了。
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
//Deal with arguments and send them to the correct functions
if (argc >= 2){
string op = argv[2];
if (op == "-a" || op == "--automatic"){
cout << "Test";
}
return 0;
}
//Or, just write help and info
cout << "n";
cout << "bwc v0.0.1U-(Unstable)nn";
cout << "Usage: bwc <operation> [...]n";
cout << "Operations:n";
cout << " bwc {-a --automatic} <file(s)>n";
cout << " bwc {-i --interactive}n";
cout << " bwc {-c --error-codes}n";
cout << "n";
return 0;
}
您对argv[]
的索引已关闭一。更改:
string op = argv[2];
至:
string op = argv[1];
相关文章:
- 分段故障(堆芯转储)矢量
- Cppcheck生成xml转储文件
- 如何找出GDB的SIGTRAP核心转储的根本原因
- C++映射分割错误(核心转储)
- 在c++中初始化矩阵时出现分段错误(核心转储)
- 在c++中键入向量中的所有值后,得到分段错误(核心转储)
- 浮点异常(核心转储)#694457
- 分段错误(核心转储)但无法弄清楚
- 链接到libkcapi时没有核心转储
- 检测到堆栈粉碎:已终止 中止(核心已转储)
- 正在处理故障(堆芯转储)
- 分段错误(核心转储) - 使用 SavedModel 的 Tensorflow C++ API 进行推断
- 我不知道为什么这段代码会让核心被转储?
- C++运行时错误与快速排序算法抛出堆栈转储错误
- 在基数排序中,我得到 munmap_chunk():无效指针和中止(核心转储).为什么?
- C++指针无法在函数外部传递值和分段错误(核心转储)错误
- cygwin_exception::open_stackdumpfile:将堆栈跟踪转储到 class4.exe.sta
- C++快速将 int 数组内容转储到文本文件中
- 合并排序:分段错误核心转储
- WinDbg 不显示某些小型转储文件的完整堆栈跟踪