Hi I'm having some trouble with a linking error in C++ and I'm not sure why it is happening, so hopefully someone here can help me, the errors is LNK1120 and LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ). The code can be seen below:
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;
}
}