忽略 sprintf* 函数中的白色 space 字符
Ignore white space characters in the sprintf* functions
我想使用 sprintf_s
函数输出一些文本。这是代码:
sprintf_s(g_msgbuf, "\n\
Active Weapon PID: %d\n\
HitMode: %s\n\
Armor DT: %d\n\
Armor DR: %d\n",
ActiveWeaponPID,
HitModeStr.c_str(),
cur_dmg_thresh,
cur_dmg_resist
);
正如人们所看到的那样,出于可读性原因,我将所有参数放在了不同的行中。问题是我在格式字符串参数之间生成了额外不需要的白色 space 字符(制表符):
Active Weapon PID: 8
HitMode: single
Armor DT: 4
Armor DR: 30
sprintf 的函数(特别是sprintf_s
)是否有way/parameter/option 来忽略多余的制表符?
您可以使用这样一个事实,即无论 whitespace/new 行之间是什么,单独的字符串都会被连接起来 - "one" "two" "three"
等同于 "onetwothree"
sprintf_s(g_msgbuf, "\n"
"Active Weapon PID: %d\n"
"HitMode: %s\n"
"Armor DT: %d\n"
"Armor DR: %d\n",
ActiveWeaponPID,
HitModeStr.c_str(),
cur_dmg_thresh,
cur_dmg_resist
);
下面是一个使用 C++ 的字符串流的例子。
#include <iostream>
#include <sstream>
std::stringstream g_msgbuf;
int main()
{
int ActiveWeaponPID{ 4 };
std::string HitMode{ "none" };
int cur_dmg_thresh{ 3 };
int cur_dmg_resist{ 5 };
g_msgbuf
<< "Active Waepon PID: " << ActiveWeaponPID << "\n"
<< "HitMode: " << HitMode << "\n"
<< "Armor DT: " << cur_dmg_thresh << "\n"
<< "Armor DR: " << cur_dmg_resist << "\n";
std::cout << g_msgbuf.str();
};
我想使用 sprintf_s
函数输出一些文本。这是代码:
sprintf_s(g_msgbuf, "\n\
Active Weapon PID: %d\n\
HitMode: %s\n\
Armor DT: %d\n\
Armor DR: %d\n",
ActiveWeaponPID,
HitModeStr.c_str(),
cur_dmg_thresh,
cur_dmg_resist
);
正如人们所看到的那样,出于可读性原因,我将所有参数放在了不同的行中。问题是我在格式字符串参数之间生成了额外不需要的白色 space 字符(制表符):
Active Weapon PID: 8
HitMode: single
Armor DT: 4
Armor DR: 30
sprintf 的函数(特别是sprintf_s
)是否有way/parameter/option 来忽略多余的制表符?
您可以使用这样一个事实,即无论 whitespace/new 行之间是什么,单独的字符串都会被连接起来 - "one" "two" "three"
等同于 "onetwothree"
sprintf_s(g_msgbuf, "\n"
"Active Weapon PID: %d\n"
"HitMode: %s\n"
"Armor DT: %d\n"
"Armor DR: %d\n",
ActiveWeaponPID,
HitModeStr.c_str(),
cur_dmg_thresh,
cur_dmg_resist
);
下面是一个使用 C++ 的字符串流的例子。
#include <iostream>
#include <sstream>
std::stringstream g_msgbuf;
int main()
{
int ActiveWeaponPID{ 4 };
std::string HitMode{ "none" };
int cur_dmg_thresh{ 3 };
int cur_dmg_resist{ 5 };
g_msgbuf
<< "Active Waepon PID: " << ActiveWeaponPID << "\n"
<< "HitMode: " << HitMode << "\n"
<< "Armor DT: " << cur_dmg_thresh << "\n"
<< "Armor DR: " << cur_dmg_resist << "\n";
std::cout << g_msgbuf.str();
};