我很关注我自己,但这里就是我所拥有的。我最近才开始熟悉指针,更多地指出我使用它们更舒适的一点,但是我发现strcpy_s()中的缓冲区太小。使用指向char数组指针的strcpy_s()的C++指针
请不要评论我使用char数组而不是std :: string,它以HL数组为中心(不知道为什么),所以我只是坚持使用模式。
void func_a()
{
char *szUserID = new char[64];
char *szInviterID = new char[64];
char *szGroupID = new char[64];
sprintf(szUserID, "%I64d", GetCommunityID(szUserSteamID));
sprintf(szInviterID, "%I64d", GetCommunityID(g_CvarSteamID.GetString()));
GetGroupCommunityID(1254745, &szGroupID); // Group Steam Community ID
}
void GetGroupCommunityID(int groupID, char **communityID)
{
int staticID = 1035827914;
int newGroupID = 29521408 + groupID;
char *buffer = new char[64];
snprintf(buffer, sizeof(buffer), "%d%d", staticID, newGroupID);
strcpy_s(*communityID, sizeof(*communityID), buffer);
delete buffer;
}
如果你需要一个动态分配的`char`数组,你通常可以使用`std :: vector`离开。我不明白为什么这不起作用。 –
2010-11-23 01:47:07
为什么新建和删除可以在堆栈中声明的完美的char缓冲区? – 2010-11-23 03:46:31