c++ - file.exe 在 Visual Studio C++ 中触发了一个断点
问题描述
抱歉,这一定是一个非常基本的错误,但我到处搜索,似乎无法解决我的问题,我只是为我的 OOP 类做一些“输入和输出数组”,我对我的数组使用动态允许,这是我的代码,我知道这只是删除错误,其他(创建,插入,...工作正常),非常感谢所有人:
我delete [] a;
delete a
也试过了,但没用,我试着把它放在system("pause")
后面(我用谷歌搜索了这个),但也没有:((
void shift_left_array(int *a,int k , int &n, int step = 1) {
// k : begin position
// n : end position
for (int i = k; i < n; i++) {
*(a + i - 1) = *(a + i); // Shift right array
}
}
void delete_from_array(int *a, int &n) {
int k; // delete position
// shift left, then resize array
cout << "Which position do you want to delete ? (Type from 0 to " << n - 1 << ") : " << endl;
cin >> k;
shift_left_array(a, k + 1, n);
n--; // resize array
delete (a + n); // Trigger break point error here
}
int main() {
int n = 0;
int *a = new int[n];
cout << "Insert array size : " << endl;
cin >> n;
// Create new array
create_array(a,n);
display_array(a,n);
// Add more value to array (increase array size)
insert_to_array(a, n);
display_array(a, n);
// Delete value from array
delete_from_array(a,n);
display_array(a, n);
// Sort
bubble_sort(a,n);
display_array(a, n);
// Search
linear_search_array(a, n);
// Update
update_array_value(a, n);
display_array(a, n);
system("pause");
return 0;
}
解决方案
推荐阅读
- python - 为什么 SocketIO 和 SSLify 不能一起工作?
- c# - 在 c# wpf 中键绑定到按钮元素
- azure - 使用具有 azure 功能的 azure service bus 进行 ERP 订单导入的最佳方法
- amazon-cloudformation - 使用 CDK 为管道 github 源 webhook 动态设置 targetPipelineVersion
- c++ - C ++函数将基类指针解析为派生类指针
- microservices - 你如何发布微服务?
- ssh - 是否可以在 SSH 终端中使用“code”命令在本地机器上使用 SSH 扩展打开 VS Code?
- ios - UIWebView 中未显示 iOS pdf 数字签名
- javascript - 所有版本的 Firefox 中的键码都相同吗?
- google-bigquery - 如何下载 Bigquery 用户列表?