">":已签名/未签名不匹配。我该如何解决这个问题?


std::string text;
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // Gets the console handle.
PCONSOLE_SCREEN_BUFFER_INFO lpScreenInfo = new CONSOLE_SCREEN_BUFFER_INFO(); // Creates a pointer to the Screen Info pointing to a temporal screen info.
GetConsoleScreenBufferInfo(hConsole, lpScreenInfo); // Saves the console screen info into the lpScreenInfo pointer.
COORD NewSBSize = lpScreenInfo->dwSize; // Gets the size of the screen
int choice{};

do
{

if (NewSBSize.X > text.size())
{
int newpos = ((NewSBSize.X - text.size()) / 2); // Calculate the number of spaces to center the specific text.

for (int i = 0; i < newpos; i++) std::cout << "ARESn"; // Prints the spaces
int newpos1 = ((NewSBSize.X - text.size()) / 2); // Calculate the number of spaces to center the specific text.

for (int i = 0; i < newpos; i++) std::cout << "MENUn"; // Prints the spaces

int newpos2 = ((NewSBSize.X - text.size()) / 2); // Calculate the number of spaces to center the specific text.

for (int i = 0; i < newpos; i++) std::cout << "Select one of the following options by pressing 1, 2 or 3:n"; // Prints the spaces
int newpos3 = ((NewSBSize.X - text.size()) / 2); // Calculate the number of spaces to center the specific text.

for (int i = 0; i < newpos; i++) std::cout << "1. Activate Virusn"; // Prints the spaces
int newpos4 = ((NewSBSize.X - text.size()) / 2); // Calculate the number of spaces to center the specific text.

for (int i = 0; i < newpos; i++) std::cout << "2. Program Informationn"; // Prints the spaces
int newpos5 = ((NewSBSize.X - text.size()) / 2); // Calculate the number of spaces to center the specific text.

for (int i = 0; i < newpos; i++) std::cout << "3. Exitn"; // Prints the spaces
std::cin >> choice; 

switch (choice)
{

case 1:

int newpos = ((NewSBSize.X - text.size()) / 2); // Calculate the number of spaces to center the specific text.
for (int i = 0; i < newpos; i++) std::cout << "Infection Initiated. Press any key to continue . . .n"; // Prints the spaces
std::cin.ignore();
system("CLS");
Ares();

case 2:

int newposi = ((NewSBSize.X - text.size()) / 2); // Calculate the number of spaces to center the specific text.
for (int i = 0; i < newposi; i++) std::cout << "Program Information loading. Press any key to continue . . .n"; // Prints the spaces
std::cin.ignore();
system("CLS");
ProgramInfo();

case 3:

int newposh = ((NewSBSize.X - text.size()) / 2); // Calculate the number of spaces to center the specific text.
for (int i = 0; i < newposh; i++) std::cout << "Ending Operations. Press any key to continue . . .n"; // Prints the spaces
std::cin.ignore();
system("CLS");
menu();

default:

int newposa = ((NewSBSize.X - text.size()) / 2); // Calculate the number of spaces to center the specific text.
for (int i = 0; i < newposa; i++) std::cout << "Invalid input! Press any key to continue . . .n"; // Prints the spaces

}
}

} 
while (choice < 1 or choice > 3);

这是我得到错误的相关代码。如果你需要查看更多我的代码,请告诉我,我会添加它。

我在互联网上寻找解决方案,发现了与我类似的问题,但这些维修工作都没有解决问题。如有任何帮助,将不胜感激

有符号/无符号不匹配。我该如何解决这个问题?

从窄到宽。如果无符号类型更宽,则首先考虑负值。

如果相对宽度不确定,请先处理负值。


NewSBSize.X显然是一个short,一个符号类型。

text.size()是一个size_t,一个无符号类型。

如果NewSBSize.X出乎意料地为负,那么NewSBSize.X > text.size()在逻辑上为假,所以在这种情况下会失败。

if (NewSBSize.X >= 0 && ....

然后将short转换为其无符号对应项,或其无符号升级对应项。此处的强制转换不会对NewSBSize.X进行值更改,下面的无符号比较基于两个无符号类型中较宽的一个进行。

... (unsigned) NewSBSize.X > text.size()

总计

if (NewSBSize.X >= 0 && (unsigned) NewSBSize.X > text.size()) {

如果代码可以确保NewSBSize.X >= 0,则简化为以下内容
警告:微优化是邪恶的。

if ((unsigned) NewSBSize.X > text.size()) {