c++ - 将 C++ 代码从一个程序转移到另一个程序

标签 c++ visual-c++ libraries

<分区>

所以,我的 friend 告诉我他设法建立了自己的 "Enigma Machine" ,但他使用的程序不适用于我的 Windows 版本。

我昨天安装了 Microsoft 的 visual studio,但无法让他的代码在我的代码上运行。我对编码还很年轻,我希望这里有人能帮助我。我相信问题出在库上,我已经尝试了所有我知道的方法,但我不确定我还需要做些什么,它给了我很多错误,并且忽略了预编译的头文件。

代码如下:

#include "iostream"
#include "cstdlib"
#include "string"
#include "stdafx.h" //I added this library because vstudio asked me to do so..?
#include "algorithm"

using namespace std;
int i, j, l, r1, r2, r3, n1, n2, n3, n4, rII, rIII;

string msg;

int rotor1[26] = { 4,10,12,5,11,6,3,16,21,25,13,19,14,22,24,7,23,20,18,15,0,8,1,17,2,9 };
int rotor2[26] = { 0,9,3,10,18,8,17,20,23,1,11,7,22,19,12,2,16,6,25,13,15,24,5,21,14,4 };
int rotor3[26] = { 1,3,5,7,9,11,2,15,17,19,23,21,25,13,24,4,8,22,6,0,10,12,20,18,16,14 };
int reflec[26] = { 24,17,20,7,16,18,11,3,15,23,13,6,14,10,12,8,4,1,5,25,2,22,21,9,0,19 };
char base[26] = { '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' };
void RotorInput() {
    cout << "Input initial positions (0 to 25):\n";
    cout << "First rotor: ";
    cin >> r1;
    cout << "Second rotor: ";
    cin >> r2;
    cout << "Third rotor: ";
    cin >> r3;
}
void RotorInitialization() {
    rotate(rotor1, rotor1 + r1, rotor1 + 26);
    rotate(rotor2, rotor2 + r2, rotor2 + 26);
    rotate(rotor2, rotor2 + r2, rotor2 + 26);
}
void MessageInput() {
    cout << "Input your message/code:\n";
    getline(cin, msg);
    getline(cin, msg);
}
void Encription() {
    l = msg.size();
    for (j = 0; j < l; j++) {

    }
    for (i = 0; i < l; i++) {

        if (msg.at(i) == ' ') {
            cout << " ";
        }
        else {
            int x = distance(base, find(base, base + 26, msg.at(i)));
            n1 = rotor1[x];
            n2 = rotor2[n1];
            n3 = rotor3[n2];
            n4 = reflec[n3];
            n3 = distance(rotor3, find(rotor3, rotor3 + 26, n4));
            n2 = distance(rotor2, find(rotor2, rotor2 + 26, n3));
            n1 = distance(rotor1, find(rotor1, rotor1 + 26, n2));
            cout << base[n1];

            rII = (i + r2 + 1) % 26;
            rIII = (i + r3 + 1) % 676;

            rotate(rotor1, rotor1 + 1, rotor1 + 26);

            if (rII == 0) {
                rotate(rotor2, rotor2 + 1, rotor2 + 26);
            }
            else {}

            if (rIII == 0) {
                rotate(rotor3, rotor3 + 1, rotor3 + 26);
            }
            else {}
        }
    }
}
int main()
{
    RotorInput();
    RotorInitialization();
    MessageInput();
    Encription();
    cout << endl;
    system("pause");
    return 0;
}

提前致谢!

最佳答案

首先,预编译头包含应该是源文件中的第一行。

此外,我会将所有标准库中的内容替换为 "通过 <>分别为开盘价或收盘价。

关于c++ - 将 C++ 代码从一个程序转移到另一个程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34118271/

相关文章:

c++ - 为什么析构函数不会在您返回的对象上被调用?

c++ - Visual C++ 生成错误 : Failed to register output

c# - 使用异常处理(可能改变)库的错误代码

java - 包装第三方库时包装异常

c++ - 更改 DEF 文件中的函数签名

macos - 使用非 native 库 (OpenCV) 在 OSX 上部署应用程序

C++ Linux 服务 - 如何使用 init.d + 自动重启?

c++ - 迭代 C++ 容器时是否可以定义 'step' 大小?

c++ - LLVM StoreInst 和 AllocaInst

c++ - 为什么在 CToolBar 中使用高深度颜色的禁用按钮只是灰色框?