Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
出于某种原因,我的sprintf调用影响了我用来格式化新字符串的字符串。这是我的代码:
sprintf
string foo = "bar"; char salt[] = ""; sprintf(salt, "%c%c", foo[0], foo[1]);
foo当我在 之后尝试打印时sprintf,它没有任何价值。如果我在 sprintf 之前打印它,那很好。
foo
您的结果缓冲区(salt)太小而无法容纳该值。
salt
string foo = "bar"; char salt[3] = ""; sprintf(salt, "%c%c", foo[0], foo[1]);