凯撒密码程序中"Debug Assertion Failed!"问题
"Debug Assertion Failed!" issue in a Caesar Cipher program
你好!
目前正在C++创建一个程序,其目的是使用Caesar Cipher加密短语,并且在Visual Studio 2017社区中多次尝试调试后无法弄清楚这里的问题是什么Microsoft。
问题
reference operator[](const size_type _Off)
{ // subscript mutable sequence
_IDL_VERIFY(_Off <= this->_Mysize(), "string subscript out of range"); //(Here, a breakpoint is triggered)
return (this->_Myptr()[_Off]);
}
错误列表中没有显示任何错误或警告,但在运行时,我的程序"跳转"到一个名为"xstring"的库中并在此函数中停止(请参阅代码(。
调试输出
Debug Assertion Failed!
Program: C:Windowssystem32MSVCP140D.dll
File: c:program files (x86)microsoft visual studio2017communityvctoolsmsvc14.10.25017includexstring
Line: 2944
Expression: string subscript out of range
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
<小时 />加密功能
int encrypt(string plainText, string cipherText, int length, int key)
{
int charLength = (int)plainText.length();
if (key < 0)
{
return -1;
}
for (int i = 0; i < charLength; i++)
{
if (isalpha(plainText[i]))
{
plainText[i] = tolower(plainText[i]);
cipherText[i] = plainText[i];
for (int j = 0; j < key; j++)
{
if (cipherText[i] == 'z')
{
cipherText[i] = 'a';
}
cipherText[i]++;
}
}
}
return charLength;
}
在写入密文之前,您从不检查密文的大小。你确定它的大小合适吗?鉴于您遇到的错误和我们获得的少量信息,这将是原因。
尝试添加
cipherText.resize(charLength);
int charLength = (int)plainText.length();
之后
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- Project Euler问题4的错误解决方案
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 一个关于在C++中重载布尔运算符的问题
- 首要问题的答案让值班员搞错了
- setlocale的C++土耳其字符串问题
- 如何重构类层次结构以避免菱形问题
- 凯撒密码程序中"Debug Assertion Failed!"问题
- "Debug assertion failed" 这种有什么问题?它应该按年份对包含电影对象的动态列表进行排序