密码不起作用 我最近开始学习C++,我一直在尝试创建挑战自我的解决方案,其中一个挑战是加密文本并最终将其保存到文本文件的密码。我当前使用的代码将无法编译,因为它无法识别replace语句,这是我目前使用的代码 #include "stdafx.h" #include <iostream> #include <fstream> #include <Windows.h> #include <string> int main() { // declare all variables std::string text; std::string s; std::string uncipheredText; //Introducing the program std::cout << "Welcome to Cipher." << std::endl; //Asks the user to input the text they want to encrypt and saves it to the unciphered text variable. std::cout << "Enter the text you want to cipher" << std::endl; std::cin >> s; //replaces all characters in the variable "s" std::replace(s.begin(), s.end(), 'Q', 'M'); std::replace(s.begin(), s.end(), 'E', 'B'); std::replace(s.begin(), s.end(), 'T', 'C'); std::replace(s.begin(), s.end(), 'U', 'Z'); std::replace(s.begin(), s.end(), 'O', 'S'); std::replace(s.begin(), s.end(), 'L', 'F'); std::replace(s.begin(), s.end(), 'J', 'H'); std::replace(s.begin(), s.end(), 'G', 'K'); std::replace(s.begin(), s.end(), 'D', 'P'); std::replace(s.begin(), s.end(), 'A', 'I'); std::replace(s.begin(), s.end(), 'X', 'Y'); std::replace(s.begin(), s.end(), 'V', 'R'); std::replace(s.begin(), s.end(), 'N', 'W'); std::replace(s.begin(), s.end(), ' ', '#'); s = text; std::cout << "Encrypted Text: " << text << std::endl; //replaces all characters in the variable "s" std::replace(s.begin(), s.end(), 'Q', 'M'); std::replace(s.begin(), s.end(), 'E', 'B'); std::replace(s.begin(), s.end(), 'T', 'C'); std::replace(s.begin(), s.end(), 'U', 'Z'); std::replace(s.begin(), s.end(), 'O', 'S'); std::replace(s.begin(), s.end(), 'L', 'F'); std::replace(s.begin(), s.end(), 'J', 'H'); std::replace(s.begin(), s.end(), 'G', 'K'); std::replace(s.begin(), s.end(), 'D', 'P'); std::replace(s.begin(), s.end(), 'A', 'I'); std::replace(s.begin(), s.end(), 'X', 'Y'); std::replace(s.begin(), s.end(), 'V', 'R'); std::replace(s.begin(), s.end(), 'N', 'W'); std::replace(s.begin(), s.end(), ' ', '#'); s = uncipheredText; std::cout << "Decrypted Text: " << uncipheredText << std::endl; /* ofstream myfile; myfile.open("dump.txt"); myfile << text; myfile.close(); */ return 0; } #包括“stdafx.h” #包括 #包括 #包括 #包括 int main() { //声明所有变量 std::字符串文本; std::字符串s; std::字符串未加密文本; //节目介绍 std::cout

密码不起作用 我最近开始学习C++,我一直在尝试创建挑战自我的解决方案,其中一个挑战是加密文本并最终将其保存到文本文件的密码。我当前使用的代码将无法编译,因为它无法识别replace语句,这是我目前使用的代码 #include "stdafx.h" #include <iostream> #include <fstream> #include <Windows.h> #include <string> int main() { // declare all variables std::string text; std::string s; std::string uncipheredText; //Introducing the program std::cout << "Welcome to Cipher." << std::endl; //Asks the user to input the text they want to encrypt and saves it to the unciphered text variable. std::cout << "Enter the text you want to cipher" << std::endl; std::cin >> s; //replaces all characters in the variable "s" std::replace(s.begin(), s.end(), 'Q', 'M'); std::replace(s.begin(), s.end(), 'E', 'B'); std::replace(s.begin(), s.end(), 'T', 'C'); std::replace(s.begin(), s.end(), 'U', 'Z'); std::replace(s.begin(), s.end(), 'O', 'S'); std::replace(s.begin(), s.end(), 'L', 'F'); std::replace(s.begin(), s.end(), 'J', 'H'); std::replace(s.begin(), s.end(), 'G', 'K'); std::replace(s.begin(), s.end(), 'D', 'P'); std::replace(s.begin(), s.end(), 'A', 'I'); std::replace(s.begin(), s.end(), 'X', 'Y'); std::replace(s.begin(), s.end(), 'V', 'R'); std::replace(s.begin(), s.end(), 'N', 'W'); std::replace(s.begin(), s.end(), ' ', '#'); s = text; std::cout << "Encrypted Text: " << text << std::endl; //replaces all characters in the variable "s" std::replace(s.begin(), s.end(), 'Q', 'M'); std::replace(s.begin(), s.end(), 'E', 'B'); std::replace(s.begin(), s.end(), 'T', 'C'); std::replace(s.begin(), s.end(), 'U', 'Z'); std::replace(s.begin(), s.end(), 'O', 'S'); std::replace(s.begin(), s.end(), 'L', 'F'); std::replace(s.begin(), s.end(), 'J', 'H'); std::replace(s.begin(), s.end(), 'G', 'K'); std::replace(s.begin(), s.end(), 'D', 'P'); std::replace(s.begin(), s.end(), 'A', 'I'); std::replace(s.begin(), s.end(), 'X', 'Y'); std::replace(s.begin(), s.end(), 'V', 'R'); std::replace(s.begin(), s.end(), 'N', 'W'); std::replace(s.begin(), s.end(), ' ', '#'); s = uncipheredText; std::cout << "Decrypted Text: " << uncipheredText << std::endl; /* ofstream myfile; myfile.open("dump.txt"); myfile << text; myfile.close(); */ return 0; } #包括“stdafx.h” #包括 #包括 #包括 #包括 int main() { //声明所有变量 std::字符串文本; std::字符串s; std::字符串未加密文本; //节目介绍 std::cout,c++,compiler-errors,C++,Compiler Errors,正如@Algirdas Preidžius在评论中提到的,您需要包括算法库。此外,您复制了以下代码: //replaces all characters in the variable "s" std::replace(s.begin(), s.end(), 'Q', 'M'); std::replace(s.begin(), s.end(), 'E', 'B'); std::replace(s.begin(), s.end(), 'T', 'C'); std::replace(s.begin(

正如@Algirdas Preidžius在评论中提到的,您需要包括算法库。此外,您复制了以下代码:

//replaces all characters in the variable "s"
std::replace(s.begin(), s.end(), 'Q', 'M');
std::replace(s.begin(), s.end(), 'E', 'B');
std::replace(s.begin(), s.end(), 'T', 'C');
std::replace(s.begin(), s.end(), 'U', 'Z');
std::replace(s.begin(), s.end(), 'O', 'S');
std::replace(s.begin(), s.end(), 'L', 'F');
std::replace(s.begin(), s.end(), 'J', 'H');
std::replace(s.begin(), s.end(), 'G', 'K');
std::replace(s.begin(), s.end(), 'D', 'P');
std::replace(s.begin(), s.end(), 'A', 'I');
std::replace(s.begin(), s.end(), 'X', 'Y');
std::replace(s.begin(), s.end(), 'V', 'R');
std::replace(s.begin(), s.end(), 'N', 'W');
std::replace(s.begin(), s.end(), ' ', '#');

您看过的文档了吗?如果看过,您就会知道它是在
中定义的。是否包括它?s=文本不是“文本”这只是一个空字符串。你写的作业方式不对。你的加密和解密提醒一样:C++中的字符是区分大小写的,A。k` q’=‘q’。也见“ToupP<代码>,<代码> ToWoW'和<代码>转换< /C>。