386*_*386 1 c++ visual-studio-2022
我的程序在 IDE (Visual Studio 2022) 中的调试和发布模式下运行良好。
当我进行构建并想要.exe从资源管理器启动时,它会启动并运行,但是......好吧,看看:
事情应该是这样的:

这是在 VS 之外的样子:

到目前为止,我已尝试将运行时库设置为多线程(/MT),但这不起作用。
除此之外,我似乎真的找不到太多东西。独立版似乎.exe缺少一些依赖项,但我不知道我需要做什么。根据我的理解,我包含在标头中的所有内容也应该被编译“到”中.exe。
似乎int128_t不起作用。ANSI 颜色代码也没有。不过,计时器正在工作。
代码:
#include <iostream>
#include <chrono>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
bool isPrime(mp::int128_t n);
mp::int128_t n{ 0 }, y{ 0 };
int main()
{
std::cin >> y;
std::cin >> n;
std::cout << "\n";
for (y; y <= n; y++)
{
int lengthy = to_string(y).length();
const auto start = std::chrono::steady_clock::now();
if (isPrime(y) == true)
std::cout << "\033[1;7;32m" << std::setw(lengthy) << std::left << y << "\033[0m ";
else
{
std::cout << std::setw(lengthy) << std::left << y << " ";
}
const auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> elapsed = end - start;
if (elapsed.count() >= 0.1)
std::cout << "\033[1;7;36m" << std::setw(10) << std::left << elapsed.count() << "\033[0m ";
else
{
std::cout << "\033[1;36m" << std::setw(10) << std::left << elapsed.count() << "\033[0m ";
}
}
std::cout << "\n";
std::cin >> y;
}
bool isPrime(mp::int128_t n)
{
if (n == 2 || n == 3)
return true;
if (n <= 1 or n % 2 == 0 or n % 3 == 0)
return false;
for (uint64_t i = 5; i * i <= n; i += 6)
{
if (n % i == 0 or n % (i + 2) == 0)
return false;
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
我已经能够使用以下代码在默认 Windows 终端中启用颜色代码:
#ifdef _WIN32
#include <Windows.h>
void enableColors()
{
DWORD consoleMode;
HANDLE outputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
if (GetConsoleMode(outputHandle, &consoleMode))
{
SetConsoleMode(outputHandle, consoleMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
}
}
#endif
Run Code Online (Sandbox Code Playgroud)
在函数开始时调用一次main。