char c2[20] = "ganquanfu";
char c1[256];
c1[sizeof(c1)-1] = 0;
_snprintf(c1, sizeof(c1), "%s", c2);
if(c1[sizeof(c1)-1]!=0)
{
cout << "warning: string is truncated" <<endl;
c1[sizeof(c1)-1]=0;
}
cout << c1 << endl;
转载于:https://www.cnblogs.com/ganquanfu2008/p/3180804.html