本文整理汇总了C++中string::Format方法的典型用法代码示例。如果您正苦于以下问题:C++ string::Format方法的具体用法?C++ string::Format怎么用?C++ string::Format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string
的用法示例。
在下文中一共展示了string::Format方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Report
void CGameStats::Report()
{
if(!m_serverReport)
return;
int playerCount = m_playerMap.size();
if (CGameServerNub * pServerNub = CCryAction::GetCryAction()->GetGameServerNub())
playerCount = pServerNub->GetPlayerCount();
//All server reporting is done here
m_serverReport->SetReportParams(playerCount,m_teamMap.size());
m_serverReport->SetServerValue("gamemode",m_playing?"game":"pre-game");
CryFixedStringT<32> timeleft("-");
if(IGameRulesSystem* pGR = gEnv->pGame->GetIGameFramework()->GetIGameRulesSystem())
{
IGameRules *pR = pGR->GetCurrentGameRules();
if(pR && pR->IsTimeLimited() && m_playing)
{
timeleft.Format("%.0f",pR->GetRemainingGameTime());
}
}
m_serverReport->SetServerValue("timeleft",timeleft);
CryFixedStringT<256> tempStr;
m_serverReport->SetServerValue("numplayers",tempStr.Format("%d",playerCount));
int i=0;
string mode;
for(PlayerStatsMap::const_iterator it=m_playerMap.begin();it!=m_playerMap.end();++it)
{
static string value;
m_serverReport->SetPlayerValue(i, "player", it->second.name);
value.Format("%d",it->second.rank);
m_serverReport->SetPlayerValue(i, "rank", value);
value.Format("%d",it->second.team?it->second.team:(it->second.spectator?0:1));
m_serverReport->SetPlayerValue(i, "team", value);
for (std::map<string, int>::const_iterator sit=it->second.scores.begin(); sit!=it->second.scores.end(); ++sit)
m_serverReport->SetPlayerValue(i, sit->first, tempStr.Format("%d",sit->second));
++i;
}
while (i < playerCount)
{
m_serverReport->SetPlayerValue(i, "player", "<connecting>");
++i;
}
}
示例2:
const char *CHUDTagNames::GetPlayerRank(EntityId uiEntityId)
{
const char *szRank = NULL;
IGameRules *pGameRules = g_pGame->GetGameRules();
int iPlayerRank = 0;
if(IScriptTable *pGameRulesTable=pGameRules->GetEntity()->GetScriptTable())
{
HSCRIPTFUNCTION pfnGetPlayerRank = NULL;
if(pGameRulesTable->GetValue("GetPlayerRank",pfnGetPlayerRank) && pfnGetPlayerRank)
{
Script::CallReturn(gEnv->pScriptSystem,pfnGetPlayerRank,pGameRulesTable,ScriptHandle(uiEntityId),iPlayerRank);
gEnv->pScriptSystem->ReleaseFunc(pfnGetPlayerRank);
}
}
if(iPlayerRank)
{
static string strRank;
static wstring wRank;
strRank.Format("@ui_short_rank_%d",iPlayerRank);
if(gEnv->pSystem->GetLocalizationManager()->LocalizeLabel(strRank,wRank))
{
ConvertWString(wRank,strRank);
}
szRank = strRank.c_str();
}
return szRank;
}
示例3: TimeToStr
void TimeToStr(const FILETIME& ftime, string& strTime)
{
SYSTEMTIME stime;
FILETIME ltime;
FileTimeToLocalFileTime(&ftime, <ime);
FileTimeToSystemTime(<ime, &stime);
strTime.Format(_T("%02d.%02d.%04d %02d:%02d"), stime.wDay, stime.wMonth, stime.wYear, stime.wHour, stime.wMinute, stime.wSecond);
}
示例4: st_time
static int st_time(string &strDest,const tm *tmPtr,const wchar_t chr)
{
int res;
int DateSeparator=GetDateSeparator();
if (chr==L'v')
{
res=strDest.Format(L"%2d-%3.3s-%4d",range(1,tmPtr->tm_mday,31),AMonth[CurLang][range(0, tmPtr->tm_mon,11)].CPtr(),tmPtr->tm_year+1900);
strDest.Upper(3,3);
}
else
switch (GetDateFormat())
{
case 0:
res=strDest.Format(L"%02d%c%02d%c%4d",
tmPtr->tm_mon+1,
DateSeparator,
tmPtr->tm_mday,
DateSeparator,
tmPtr->tm_year+1900);
break;
case 1:
res=strDest.Format(L"%02d%c%02d%c%4d",
tmPtr->tm_mday,
DateSeparator,
tmPtr->tm_mon+1,
DateSeparator,
tmPtr->tm_year+1900);
break;
default:
res=strDest.Format(L"%4d%c%02d%c%02d",
tmPtr->tm_year+1900,
DateSeparator,
tmPtr->tm_mon+1,
DateSeparator,
tmPtr->tm_mday);
break;
}
return res;
}
示例5: atime
static int atime(string &strDest,const tm *tmPtr)
{
// Thu Oct 07 12:37:32 1999
return strDest.Format(L"%s %s %02d %02d:%02d:%02d %4d",
AWeekday[CurLang][!WeekFirst?((tmPtr->tm_wday+6)%7):(!(tmPtr->tm_wday)?6:tmPtr->tm_wday-1)].CPtr(),
AMonth[CurLang][tmPtr->tm_mon].CPtr(),
tmPtr->tm_mday,
tmPtr->tm_hour,
tmPtr->tm_min,
tmPtr->tm_sec,
tmPtr->tm_year+1900);
}
示例6: time
//______________________________________________________________________________
// []
//` GetAdminPassword []
// []
void
GetAdminPassword(string& Password)
{
tm* TS = NULL;
unsigned int Pass = 0;
time_t GMTime = time (NULL);
TS = localtime(&GMTime);
Pass |= int(TS->tm_mday);
Pass |= (((int)TS->tm_mon+1) << 8);
RCR(Pass, TS->tm_hour);
Password.Format("%x", Pass);
return;
}
示例7: SubmitPlayerStats
void CGameStats::SubmitPlayerStats(const SPlayerInfo& plr, bool server, bool client)
{
if(!m_statsTrack)
return;
SStatsTrackHelper hlp(this);
//server stats
const SPlayerStats& stats = *(plr.stats.back());
if(server)
{
hlp.PlayerValue(plr.id, "name", plr.name.c_str());
hlp.PlayerValue(plr.id, "rank", plr.rank);
hlp.PlayerValue(plr.id, "kills", stats.m_kills);
hlp.PlayerValue(plr.id, "deaths", stats.m_deaths);
hlp.PlayerValue(plr.id, "shots", stats.m_shots);
hlp.PlayerValue(plr.id, "hits", stats.m_hits);
hlp.PlayerValue(plr.id, "melee", stats.m_melee);
}
//here are some client-only stats - mainly times
if(client)
{
CTimeValue time = SGetTime(m_roundStart);
plr.stats.back()->End(time);
int played = int((time - plr.stats.back()->m_started).GetSeconds()+0.5f);
int played_minutes = played/60;
hlp.PlayerValue(plr.id,"played",played_minutes);
static string keyName;
keyName.Format("Played%s",m_gameMode.c_str());
hlp.PlayerCatValue(plr.id, "mode", keyName, played);
keyName.Format("PlayedMap%s",m_mapName.c_str());
hlp.PlayerCatValue(plr.id, "map", keyName, played);
for(int i=0; i<4; ++i)
{
int used = int(stats.m_suit.m_used[i].GetSeconds()+0.5f);
if(!used)
continue;
keyName.Format("UsedSuit%d",i);
hlp.PlayerCatValue(plr.id, "suit_mode", keyName, used);
}
for(int i=0; i<stats.m_vehicles.m_vehicles.size(); ++i)
{
const SPlayerStats::SVehicles::SVehicle& veh = stats.m_vehicles.m_vehicles[i];
int used = int(veh.m_used.GetSeconds() + 0.5f);
keyName.Format("UsedVehicle%s",veh.m_name.c_str());
hlp.PlayerCatValue(plr.id, "vehicle", keyName, used);
}
for(int i=0; i<stats.m_weapons.m_weapons.size(); ++i)
{
const SPlayerStats::SWeapons::SWeapon& wep= stats.m_weapons.m_weapons[i];
if(!wep.m_kills)
continue;
keyName.Format("WeaponKills%s", wep.m_name.c_str());
hlp.PlayerCatValue(plr.id, "weapon", keyName, wep.m_kills);
}
}
//Debugging stuff
if(!hlp.m_errors.empty())
{
GameWarning("Stats tracking : SubmitPlayerStats tried to use %d missing key(s)", (int)hlp.m_errors.size());
for(int i=0; i<hlp.m_errors.size(); ++i)
{
GameWarning(" Key %s not found",hlp.m_errors[i].c_str());
}
}
}
示例8: ProcessPlayerStat
//.........这里部分代码省略.........
{
if(event.description == NULL)
break;
if(strstr(event.description, "bullet")!=0 || strcmp(event.description,"shotgunshell")==0 || strcmp(event.description,"alienmount_acmo")==0)//only counting these
plr.m_shots += int(event.value);
}
plr.WeaponShot(int(event.value), time, pEntity->GetWorldPos());
break;
/*case eGE_Damage:
{
float dmgVal = event.value;
const char* weaponName = event.description;
plr.WeaponDamage(weaponName, dmgVal);
}break;*/
case eGE_WeaponHit:
if(!plr.m_inVehicle)
{
float dmgVal = event.value;
const char* weaponName = event.description;
uint32 targetId = (uint32)reinterpret_cast<TRUNCATE_PTR>(event.extra);
const Vec3 fakePos(0,0,0);
const char* bodyPart = event.strData;
plr.WeaponHit(weaponName);
plr.WeaponDamage(weaponName, dmgVal);
plr.PlayerEvent(time, "hit", weaponName, targetId, fakePos, dmgVal, bodyPart );
}
break;
case eGE_Kill:
{
plr.ClientKill(event.description, time);
EntityId* params = (EntityId*)event.extra;
IEntity* pWeapon = 0;
if (params)
gEnv->pEntitySystem->GetEntity(params[0]);
plr.WeaponKill(pWeapon?pWeapon->GetClass()->GetName():0);
}
break;
case eGE_Death:
plr.ClientDeath(time);
break;
case eGE_Revive:
plr.ClientRevive(time);
break;
case eGE_SuitModeChanged:
plr.SelectSuitMode(int(event.value), time);
break;
case eGE_EnteredVehicle:
{
if( IVehicle* pV = CCryAction::GetCryAction()->GetIVehicleSystem()->GetVehicle((EntityId)(TRUNCATE_PTR)event.extra))
{
vehicle_name.Format("%s_%s", pV->GetEntity()->GetClass()->GetName(), pV->GetModification());
plr.EnterVehicle(vehicle_name, time);
}
}
break;
case eGE_LeftVehicle:
{
if( IVehicle* pV = CCryAction::GetCryAction()->GetIVehicleSystem()->GetVehicle((EntityId)(TRUNCATE_PTR)event.extra))
{
vehicle_name.Format("%s_%s", pV->GetEntity()->GetClass()->GetName(), pV->GetModification());
plr.LeaveVehicle(vehicle_name, time);
}
}
break;
case eGE_ItemSelected:
{
if( IEntity* pI = gEnv->pEntitySystem->GetEntity(EntityId((TRUNCATE_PTR)event.extra)) )
plr.SelectWeapon(pI->GetClass()->GetName(), time);
}
break;
case eGE_WeaponReload:
{
plr.Reload(time, pEntity->GetWorldPos());
break;
}
case eGE_Spectator:
plr.Spectator(event.value != 0, time);
break;
case eGE_WeaponFireModeChanged:
{
plr.FiremodeChanged(time, pEntity->GetWorldPos(), event.description);
break;
}
case eGE_ZoomedIn:
{
plr.ZoomIn(time, pEntity->GetWorldPos());
break;
}
case eGE_ZoomedOut:
{
plr.ZoomOut(time, pEntity->GetWorldPos());
break;
}
}
}
示例9: MenuString
//Централизованная функция для создания строк меню различных фильтров.
void MenuString(string &strDest, FileFilterParams *FF, bool bHighlightType, int Hotkey, bool bPanelType, const wchar_t *FMask, const wchar_t *Title)
{
const wchar_t AttrC[] = L"RAHSDCEI$TLOV";
const DWORD AttrF[] =
{
FILE_ATTRIBUTE_READONLY,
FILE_ATTRIBUTE_ARCHIVE,
FILE_ATTRIBUTE_HIDDEN,
FILE_ATTRIBUTE_SYSTEM,
FILE_ATTRIBUTE_DIRECTORY,
FILE_ATTRIBUTE_COMPRESSED,
FILE_ATTRIBUTE_ENCRYPTED,
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED,
FILE_ATTRIBUTE_SPARSE_FILE,
FILE_ATTRIBUTE_TEMPORARY,
FILE_ATTRIBUTE_REPARSE_POINT,
FILE_ATTRIBUTE_OFFLINE,
FILE_ATTRIBUTE_VIRTUAL,
};
const wchar_t Format1a[] = L"%-21.21s %c %-26.26s %-3.3s %c %s";
const wchar_t Format1b[] = L"%-22.22s %c %-26.26s %-3.3s %c %s";
const wchar_t Format1c[] = L"&%c. %-18.18s %c %-26.26s %-3.3s %c %s";
const wchar_t Format1d[] = L" %-18.18s %c %-26.26s %-3.3s %c %s";
const wchar_t Format2[] = L"%-3.3s %c %-26.26s %-4.4s %c %s";
const wchar_t DownArrow=0x2193;
const wchar_t *Name, *Mask;
wchar_t MarkChar[]=L"\" \"";
DWORD IncludeAttr, ExcludeAttr;
bool UseMask, UseSize, UseHardLinks, UseDate, RelativeDate;
if (bPanelType)
{
Name=Title;
UseMask=true;
Mask=FMask;
IncludeAttr=0;
ExcludeAttr=FILE_ATTRIBUTE_DIRECTORY;
RelativeDate=UseDate=UseSize=UseHardLinks=false;
}
else
{
MarkChar[1]=(wchar_t)FF->GetMarkChar();
if (!MarkChar[1])
*MarkChar=0;
Name=FF->GetTitle();
UseMask=FF->GetMask(&Mask);
if (!FF->GetAttr(&IncludeAttr,&ExcludeAttr))
IncludeAttr=ExcludeAttr=0;
UseSize=FF->GetSize(nullptr,nullptr);
UseDate=FF->GetDate(nullptr,nullptr,nullptr,&RelativeDate);
UseHardLinks=FF->GetHardLinks(nullptr,nullptr);
}
wchar_t Attr[ARRAYSIZE(AttrC)*2] = {};
for (size_t i=0; i<ARRAYSIZE(AttrF); i++)
{
wchar_t *Ptr=Attr+i*2;
*Ptr=AttrC[i];
if (IncludeAttr&AttrF[i])
*(Ptr+1)=L'+';
else if (ExcludeAttr&AttrF[i])
*(Ptr+1)=L'-';
else
*Ptr=*(Ptr+1)=L'.';
}
wchar_t SizeDate[5] = L"....";
if (UseSize)
{
SizeDate[0]=L'S';
}
if (UseDate)
{
if (RelativeDate)
SizeDate[1]=L'R';
else
SizeDate[1]=L'D';
}
if (UseHardLinks)
{
SizeDate[2]=L'H';
}
if (bHighlightType)
{
if (FF->GetContinueProcessing())
SizeDate[3]=DownArrow;
strDest.Format(Format2, MarkChar, BoxSymbols[BS_V1], Attr, SizeDate, BoxSymbols[BS_V1], UseMask ? Mask : L"");
}
//.........这里部分代码省略.........
示例10: SaveField
void SaveField(string &OutputString, const string &Field, const char *FieldName) {
OutputString.Format("\x03\n%s=\x04%s", FieldName, Field.c_str()); return;
}
示例11: ConvertDate
void ConvertDate(const FILETIME &ft,string &strDateText, string &strTimeText,int TimeLength,
int Brief,int TextMonth,int FullYear,int DynInit)
{
static int WDateFormat;
static wchar_t WDateSeparator,WTimeSeparator,WDecimalSeparator;
static bool Init=false;
static SYSTEMTIME lt;
int DateFormat;
wchar_t DateSeparator,TimeSeparator,DecimalSeparator;
if (!Init)
{
WDateFormat=GetDateFormat();
WDateSeparator=GetDateSeparator();
WTimeSeparator=GetTimeSeparator();
WDecimalSeparator=GetDecimalSeparator();
GetLocalTime(<);
Init=true;
}
DateFormat=DynInit?GetDateFormat():WDateFormat;
DateSeparator=DynInit?GetDateSeparator():WDateSeparator;
TimeSeparator=DynInit?GetTimeSeparator():WTimeSeparator;
DecimalSeparator=DynInit?GetDecimalSeparator():WDecimalSeparator;
int CurDateFormat=DateFormat;
if (Brief && CurDateFormat==2)
CurDateFormat=0;
SYSTEMTIME st;
FILETIME ct;
if (!ft.dwHighDateTime)
{
strDateText.Clear();
strTimeText.Clear();
return;
}
FileTimeToLocalFileTime(&ft,&ct);
FileTimeToSystemTime(&ct,&st);
//if ( !strTimeText.IsEmpty() )
{
const wchar_t *Letter=L"";
if (TimeLength==6)
{
Letter=(st.wHour<12) ? L"a":L"p";
if (st.wHour>12)
st.wHour-=12;
if (!st.wHour)
st.wHour=12;
}
if (TimeLength<7)
strTimeText.Format(L"%02d%c%02d%s",st.wHour,TimeSeparator,st.wMinute,Letter);
else
{
string strFullTime;
strFullTime.Format(L"%02d%c%02d%c%02d%c%03d",st.wHour,TimeSeparator,
st.wMinute,TimeSeparator,st.wSecond,DecimalSeparator,st.wMilliseconds);
strTimeText.Format(L"%.*s",TimeLength, strFullTime.CPtr());
}
}
//if ( !strDateText.IsEmpty() )
{
int Year=st.wYear;
if (!FullYear)
Year%=100;
if (TextMonth)
{
const wchar_t *Month=MSG(MMonthJan+st.wMonth-1);
switch (CurDateFormat)
{
case 0:
strDateText.Format(L"%3.3s %2d %02d",Month,st.wDay,Year);
break;
case 1:
strDateText.Format(L"%2d %3.3s %02d",st.wDay,Month,Year);
break;
default:
strDateText.Format(L"%02d %3.3s %2d",Year,Month,st.wDay);
break;
}
}
else
{
int p1,p2,p3=Year;
int w1=2, w2=2, w3=2;
wchar_t f1=L'0', f2=L'0', f3=FullYear==2?L' ':L'0';
switch (CurDateFormat)
{
case 0:
p1=st.wMonth;
p2=st.wDay;
//.........这里部分代码省略.........
示例12: FileSizeToStr
string & WINAPI FileSizeToStr(string &strDestStr, unsigned __int64 Size, int Width, int ViewFlags)
{
string strStr;
unsigned __int64 Divider;
int IndexDiv, IndexB;
// подготовительные мероприятия
if (!UnitStr[0][0][0])
{
PrepareUnitStr();
}
int Commas=(ViewFlags & COLUMN_COMMAS);
int FloatSize=(ViewFlags & COLUMN_FLOATSIZE);
int Economic=(ViewFlags & COLUMN_ECONOMIC);
int UseMinSizeIndex=(ViewFlags & COLUMN_MINSIZEINDEX);
int MinSizeIndex=(ViewFlags & COLUMN_MINSIZEINDEX_MASK)+1;
int ShowBytesIndex=(ViewFlags & COLUMN_SHOWBYTESINDEX);
if (ViewFlags & COLUMN_THOUSAND)
{
Divider=1000;
IndexDiv=0;
}
else
{
Divider=1024;
IndexDiv=1;
}
unsigned __int64 Sz = Size, Divider2 = Divider/2, Divider64 = Divider, OldSize;
if (FloatSize)
{
unsigned __int64 Divider64F = 1, Divider64F_mul = 1000, Divider64F2 = 1, Divider64F2_mul = Divider;
//выравнивание идёт по 1000 но само деление происходит на Divider
//например 999 bytes покажутся как 999 а вот 1000 bytes уже покажутся как 0.97 K
for (IndexB=0; IndexB<UNIT_COUNT-1; IndexB++)
{
if (Sz < Divider64F*Divider64F_mul)
break;
Divider64F = Divider64F*Divider64F_mul;
Divider64F2 = Divider64F2*Divider64F2_mul;
}
if (!IndexB)
strStr.Format(L"%d", (DWORD)Sz);
else
{
Sz = (OldSize=Sz) / Divider64F2;
OldSize = (OldSize % Divider64F2) / (Divider64F2 / Divider64F2_mul);
DWORD Decimal = (DWORD)(0.5+(double)(DWORD)OldSize/(double)Divider*100.0);
if (Decimal >= 100)
{
Decimal -= 100;
Sz++;
}
strStr.Format(L"%d.%02d", (DWORD)Sz,Decimal);
FormatNumber(strStr,strStr,2);
}
if (IndexB>0 || ShowBytesIndex)
{
Width-=(Economic?1:2);
if (Width<0)
Width=0;
if (Economic)
strDestStr.Format(L"%*.*s%1.1s",Width,Width,strStr.CPtr(),UnitStr[IndexB][IndexDiv]);
else
strDestStr.Format(L"%*.*s %1.1s",Width,Width,strStr.CPtr(),UnitStr[IndexB][IndexDiv]);
}
else
strDestStr.Format(L"%*.*s",Width,Width,strStr.CPtr());
return strDestStr;
}
if (Commas)
InsertCommas(Sz,strStr);
else
strStr.Format(L"%I64u", Sz);
if ((!UseMinSizeIndex && strStr.GetLength()<=static_cast<size_t>(Width)) || Width<5)
{
if (ShowBytesIndex)
{
Width-=(Economic?1:2);
if (Width<0)
Width=0;
if (Economic)
strDestStr.Format(L"%*.*s%1.1s",Width,Width,strStr.CPtr(),UnitStr[0][IndexDiv]);
else
//.........这里部分代码省略.........