使用 Microsoft VS 编写程序C++,但我在这里收到调试断言消息.它可以在 cpp.sh 上运行,repl.i
Writing program in C++ using Microsoft VS, but I get a debug assertion message here. It runs on cpp.sh and repl.it fine, but not on VS. What can I do?
此函数旨在从 char 数组中删除所有特殊字符、数字和空格。
// Michael E. Torres II
// Vigenere Cipher
// February 4, 2018
// C++ code to implement Vigenere Cipher
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <cctype>
#include <iterator>
#include <sstream>
#include <functional>
using namespace std;
// This function generates the key in
// a cyclic manner until it's length isi'nt
// equal to the length of original text
string generateKey(string str, string key)
{
int x = str.size();
for (int i = 0; ; i++)
{
if (x == i)
i = 0;
if (key.size() == str.size())
break;
key.push_back(key[i]);
}
return key;
}
// This function returns the encrypted text
// generated with the help of the key
string cipherText(string str, string key)
{
string cipher_text;
for (int i = 0; i < str.size(); i++)
{
// converting in range 0-25
int x = (str[i] + key[i]) % 26;
// convert into alphabets(ASCII)
x += 'A';
cipher_text.push_back(x);
}
return cipher_text;
}
// This function decrypts the encrypted text
// and returns the original text
string originalText(string cipher_text, string key)
{
string orig_text;
for (int i = 0; i < cipher_text.size(); i++)
{
// converting in range 0-25
int x = (cipher_text[i] - key[i] + 26) % 26;
// convert into alphabets(ASCII)
x += 'A';
orig_text.push_back(x);
transform(orig_text.begin(), orig_text.end(), orig_text.begin(), ::tolower);
}
return orig_text;
}
string removeNonAlpha(char *str)
{
unsigned long i = 0;
unsigned long j = 0;
char c;
while ((c = str[i++]) != ' ')
{
if (isalpha(c)) // this is where the breakpoint is automatically placed
{
str[j++] = c;
}
}
str[j] = ' ';
return str;
}
// Driver program to test the above function
int main(int argc, char *argv[])
{
string keyword = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
stringstream ss;
char a[] = "“I think and think for months and years. Ninety-nine times, the conclusion is false. The hundredth time I am right.” – Albert Einstein “Imagination is more important than knowledge. For knowledge is limited, whereas imagination embraces the entire world, stimulating progress, giving birth to evolution.” – Albert Einstein";
int i = 0;
string str = removeNonAlpha(a);
str.append(512 - str.length(), 'X');
transform(str.begin(), str.end(), str.begin(), ::toupper);
transform(keyword.begin(), keyword.end(), keyword.begin(), ::toupper);
string key = generateKey(str, keyword);
string cipher_text = cipherText(str, key);
transform(cipher_text.begin(), cipher_text.end(), cipher_text.begin(), ::tolower);
transform(key.begin(), key.end(), key.begin(), ::tolower);
string orig = originalText(cipher_text, key);
cout << "Original/Decrypted Text : " << "n";
for (int i = 0; i < orig.size(); i += 81)
orig.insert(i, "n");
cout << orig;
cout << "nn" << "Ciphertext : " << "n";
for (int i = 0; i < cipher_text.size(); i += 81)
cipher_text.insert(i, "n");
cout << cipher_text;
cout << "nnPress ENTER key to Continuen";
getchar();
return 0;
}
char 数组可以很好地处理这个 while 循环,只要没有特殊字符 [.,%$@!^]。只要 char 数组中有任何特殊字符,它就会给我调试断言:
"程序:...\项目\控制台应用程序17\调试\控制台应用程序17.exeFile: minkernel\crts\ucrt\src\appcrt\convert\isctype.cpp行: 42
表达式: c>= -1 && c <= 255
。
程序"[11048] 控制台应用程序17.exe"已退出,代码为 3 (0x3(。
如果我在 repl.it 或 cpp.sh 上运行它,我不会遇到任何问题。我感谢任何帮助。谢谢。
它根本没有完成。它需要清理很多,但我只是想按原样测试它。
请参阅 https://msdn.microsoft.com/en-us/library/xt82b8z8.aspxISALPHA 期望一个介于 0 和 0xFF 之间的数字:
_isalpha_l如果 c 不是 EOF 或 介于 0 到 0xFF 之间(含 0 和 (。当调试 CRT 库 使用且 c 不是这些值之一,函数会引发 断言。
在传递给 isalpha 之前,您需要将字符转换为无符号字符。
相关文章:
- .cpp和.h文件中的模板专用化声明
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- Linux的Cpp上的计时器
- boost::进程间消息队列引发错误
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- 命名空间中具有.h和.cpp文件的类
- 内置函数可查看CPP中的成员变量
- 无法编译 rtmidi 测试 cmidiin.cpp 文件, 非法指令
- Cpp-Tuple使用带有变量的get
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- 有充分的理由在h文件中使用include保护而不是cpp文件吗
- 如何通过cpp程序运行shell脚本
- 在线编译器中的分段C++没有打印消息
- C++错误消息*成员参考.**初学者*
- 使用2个键的cpp-stl::优先级队列排序不正确
- 使用 Microsoft VS 编写程序C++,但我在这里收到调试断言消息.它可以在 cpp.sh 上运行,repl.i
- 如何在 cpp 中使用味精包序列化嵌套消息
- 在 qpid cpp 客户端中接收传入消息时除外
- 协议缓冲cpp嵌入的消息
- ActiveMQ-CPP -消息重新传递延迟没有得到应用