Unexpected characters in the console release

I am programming a new server-client network for the game Crysis Wars. I have a function that centers the string by the number of characters supported per-line in the console window. The window matches 113 characters, but I set the maximum width of the characters in my function to 111to fit the text.

This is my function:

string Main::CenterText(string s)
{
    return string((111 - s.length()) / 2, ' ') + s; 
}

This function is related to the question I asked last year , but I am not sure, however, whether I used it or not in past projects.

I am trying to use this function in this context (the function CryLogAlwayssimply writes a line to the game / server log file and prints it):

CryLogAlways(CenterText("   ____     ____      _ __      _  _  __").c_str());
CryLogAlways(CenterText("  /  _/__  / _(_)__  (_) /___ _( )| |/_/").c_str());
CryLogAlways(CenterText(" _/ // _ \\/ _/ / _ \\/ / __/ // //_>  <  ").c_str());
CryLogAlways(CenterText("/___/_//_/_//_/_//_/_/\\__/\\_, / /_/|_|  ").c_str());
CryLogAlways(CenterText("                         /___/          ").c_str());

However, the conclusion:

enter image description here

Similarly, since @ deW1 is requested, I have a similar output with CryLogAlways(CenterText("X").c_str());:

enter image description here

?

+4
2

string . , using namespace std - ( ), string std::string. , -, , string, - ( , ), std::string (.. .length() .c_str()). , , std::string.

, , : •

std::string Main::CenterText(std::string s)
{
    return std::string((111 - s.length()) / 2, ' ') + s; 
}

, std.

+8

++ Reference, .

, .

(111-1)/2 = 55 = '7' '' = 32 .

string(' ',(111 - s.length()) / 2)

.

+2

All Articles