【发布时间】:2022-01-20 19:47:00
【问题描述】:
我的程序在 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;
}
【问题讨论】:
-
cmd 提示符不接受您的颜色控制字符
-
@386 我的意思是
boost和isPrime以及其他所有内容。与您的std::cout的单行具有相同的问题。如上所述 - “控制台”问题 -
@386 回复:
do you see the numbers 1..100 counting up? They are not there in the second picture- 但他们是!我可以看到1duration2等 -
嗯..这很尴尬。我会将您的评论标记为已回答。对不起,谢谢你的帮助。我想我会好好睡一觉的。