【发布时间】:2017-05-11 13:42:46
【问题描述】:
你好!
目前在 C++ 中创建一个程序,其目的是用 Caesar Cipher 加密一个短语,并且在尝试了几次调试后无法弄清楚问题出在 em>Microsoft Visual Studio 2017 社区。
问题
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:\Windows\system32\MSVCP140D.dll
File: c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.10.25017\include\xstring
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;
}
【问题讨论】:
标签: c++ visual-studio-2017 assertion caesar-cipher