R6010 执行后出错.if 语句在 for 循环中.[作业][中止已解决,发现新问题]
R6010 Error after executed. If statements in for loop. [Homework] [abort resolved, new issue discovered]
我正在创建一个程序来加密或解密消息。程序执行但返回 R6010 错误,所以我假设我给出的条件有问题。但是,在开始调用中止之前,程序会保持完美运行一两次。
我正在使用Visual Studio进行C++。仍处于起步阶段/难以理解其他R6010中止错误给出的一些解决方案。也许我的代码太草率了,但我希望得到一些建议来清理它,或者至少通过中止。谢谢。
从原始代码编辑;更正了数组大小,首先在循环中检查了溢出(如果找不到字符,则更正了中止错误(,将循环更改为 do-while 循环,以及在 if 语句上将 0 更改为 -1(do-while 让程序初始化为 i=0,在循环以 ++i 增量重新启动之前需要 -1(。
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
//Initiate vectors, strings and variables.
vector<char> normalV(27);
vector<char> cipherV(27);
string toDec;
int i = 0, j = 0;
//Initiate string & decipher variables.
normalV.at(0) = 'a'; cipherV.at(0) = '!';
normalV.at(1) = 'b'; cipherV.at(1) = '^';
normalV.at(2) = 'c'; cipherV.at(2) = '&';
normalV.at(3) = 'd'; cipherV.at(3) = '*';
normalV.at(4) = 'e'; cipherV.at(4) = '@';
normalV.at(5) = 'f'; cipherV.at(5) = '(';
normalV.at(6) = 'g'; cipherV.at(6) = ')';
normalV.at(7) = 'h'; cipherV.at(7) = '-';
normalV.at(8) = 'i'; cipherV.at(8) = '#';
normalV.at(9) = 'j'; cipherV.at(9) = '_';
normalV.at(10) = 'k'; cipherV.at(10) = '=';
normalV.at(11) = 'l'; cipherV.at(11) = '+';
normalV.at(12) = 'm'; cipherV.at(12) = '[';
normalV.at(13) = 'n'; cipherV.at(13) = '{';
normalV.at(14) = 'o'; cipherV.at(14) = '$';
normalV.at(15) = 'p'; cipherV.at(15) = ']';
normalV.at(16) = 'q'; cipherV.at(16) = '}';
normalV.at(17) = 'r'; cipherV.at(17) = ';';
normalV.at(18) = 's'; cipherV.at(18) = ':';
normalV.at(19) = 't'; cipherV.at(19) = ',';
normalV.at(20) = 'u'; cipherV.at(20) = '%';
normalV.at(21) = 'v'; cipherV.at(21) = '<';
normalV.at(22) = 'w'; cipherV.at(22) = '.';
normalV.at(23) = 'x'; cipherV.at(23) = '>';
normalV.at(24) = 'y'; cipherV.at(24) = '/';
normalV.at(25) = 'z'; cipherV.at(25) = '?';
//Get user to input string
cout << "Input message to encrypt/decrypt: " << endl;
getline(cin, toDec);
//creates loop to check for each index of
do {
//cout << toDec.at(i) << endl;
//output if character not in encryption/decryption vectors.
if (i == 26) {
cout << toDec.at(j);
i = -1;
j++;
}
// Encryption
else if (normalV.at(i) == toDec.at(j)) {
cout << cipherV.at(i);
i = -1;
j++;
}
// Decryption
else if (cipherV.at(i) == toDec.at(j)) {
cout << normalV.at(i);
i = -1;
j++;
}
++i;
} while (j < toDec.length());
cout << endl;
return 0;
}
这是一个更简单的大纲:
#include <iostream>
#include <map>
using namespace std;
int main() {
std::map<char, char> encoding = {
{'a', '!'},
{'b', '^'},
{'c', '&'},
{'d', '*'},
{'e', '@'},
{'f', '('},
{'g', ')'},
{'h', '-'},
{'i', '#'},
{'j', '_'},
{'k', '='},
{'l', '+'},
{'m', '['},
{'n', '{'},
{'o', '$'},
{'p', ']'},
{'q', '}'},
{'r', ';'},
{'s', ':'},
{'t', ','},
{'u', '%'},
{'v', '<'},
{'w', '.'},
{'x', '>'},
{'y', '/'},
{'z', '?'} };
string toDec;
//Get user to input string
cout << "Input message to encrypt/decrypt: " << endl;
getline(cin, toDec);
for(char c : toDec )
{
cout << encoding.at(c);
}
return 0;
}
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 运行同一解决方案的另一个项目的项目
- C++,系统无法执行指定的程序
- 使用C++中的模板和运算符重载执行矩阵运算
- Project Euler问题4的错误解决方案
- Ardunio UNO解决了多个重叠的定时器循环
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何解决 Ninja c++ 构建和执行问题
- 无法在问题解决方案中执行输出逻辑
- 解决方案在第 25 行执行错误'out of bounds'
- 自上而下的动态规划与递归朴素解决方案.检查运行时执行
- 如何在解决方案中生成多个项目之前执行流程
- R6010 执行后出错.if 语句在 for 循环中.[作业][中止已解决,发现新问题]
- 解决rdtsc的解决方案执行
- Qt - 解决一个插槽上的两个顺序调用,并且仅执行一次操作
- 在VS2015社区版(C++)中从项目/解决方案中创建可执行文件
- 使用模板元编程执行过载解决
- 如何将c++可执行代码扩展到不同的代码层(例如产品代码、解决方案代码)
- VS2015可执行文件成为病毒(有潜在的解决方案,但不知道为什么)
- 我只能想到蛮力解决方案.如何执行递归