在C ++中链接问题

问题描述

嗨,我在C ++中出现链接错误时遇到了麻烦,我不确定为什么会发生这种情况,因此希望这里有人可以帮助我,错误是LNK1120和LNK2019未解析的外部符号_main,在函数“ int”中引用__cdecl invoke_main(void)”(?invoke_main @@ YAHXZ)。该代码可以在下面看到:

Cipher.h

#pragma once
#include <string>
#include <algorithm>

namespace ceaser {
    class Cipher
    {
    public:
        std::string FormatMessage(std::string msg);

        std::string Encrypt(std::string msg,int shift);

        std::string Decrypt(std::string encryptedText,int shift);
    };
}

Cipher.cpp

#include "Cipher.h"

namespace ceaser {
    std::string Cipher::FormatMessage(std::string msg) {
        std::transform(msg.begin(),msg.end(),msg.begin(),::toupper);

        return msg;
    }

    std::string Cipher::Encrypt(std::string msg,int shift) {
        std::string result = "";

        for (int i = 0; i < msg.length(); i++) {
            if (isupper(msg[i]))
                result += char(int(msg[i] + shift - 65) % 26 + 65);
            else
                result += msg[i];
        }

        return result;
    }

    std::string Cipher::Decrypt(std::string encryptedText,int shift) {
        return Cipher::Encrypt(encryptedText,26 - shift);
    }
}

main.cpp

#include <iostream>
#include "Cipher.h"

namespace ceaser {

    int main()
    {
        Cipher cipher;
        std::string text = "Hello World!";
        text = cipher.FormatMessage(text);
        int shift = 4;

        std::string encryptedText = cipher.Encrypt(text,shift);
        std::cout << encryptedText << std::endl;

        std::cout << "decrypting... " + cipher.Decrypt(encryptedText,shift);

        return 0;
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)