<i id='n8HSo'><tr id='n8HSo'><dt id='n8HSo'><q id='n8HSo'><span id='n8HSo'><b id='n8HSo'><form id='n8HSo'><ins id='n8HSo'></ins><ul id='n8HSo'></ul><sub id='n8HSo'></sub></form><legend id='n8HSo'></legend><bdo id='n8HSo'><pre id='n8HSo'><center id='n8HSo'></center></pre></bdo></b><th id='n8HSo'></th></span></q></dt></tr></i><div id='n8HSo'><tfoot id='n8HSo'></tfoot><dl id='n8HSo'><fieldset id='n8HSo'></fieldset></dl></div>
        <bdo id='n8HSo'></bdo><ul id='n8HSo'></ul>

      <legend id='n8HSo'><style id='n8HSo'><dir id='n8HSo'><q id='n8HSo'></q></dir></style></legend>
    1. <tfoot id='n8HSo'></tfoot>

      <small id='n8HSo'></small><noframes id='n8HSo'>

      “strcpy"和“strcpy_s"之间的区别?

      Difference between #39;strcpy#39; and #39;strcpy_s#39;?(“strcpy和“strcpy_s之间的区别?)

      <legend id='xym36'><style id='xym36'><dir id='xym36'><q id='xym36'></q></dir></style></legend>
        <tbody id='xym36'></tbody>
          • <bdo id='xym36'></bdo><ul id='xym36'></ul>
          • <tfoot id='xym36'></tfoot>

              <small id='xym36'></small><noframes id='xym36'>

                <i id='xym36'><tr id='xym36'><dt id='xym36'><q id='xym36'><span id='xym36'><b id='xym36'><form id='xym36'><ins id='xym36'></ins><ul id='xym36'></ul><sub id='xym36'></sub></form><legend id='xym36'></legend><bdo id='xym36'><pre id='xym36'><center id='xym36'></center></pre></bdo></b><th id='xym36'></th></span></q></dt></tr></i><div id='xym36'><tfoot id='xym36'></tfoot><dl id='xym36'><fieldset id='xym36'></fieldset></dl></div>
                本文介绍了“strcpy"和“strcpy_s"之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                当我尝试使用 strcpy 复制字符串时,它给了我一个编译错误.

                When i tries to use strcpy to copy a string it gave me a compile error.

                error C4996 'strcpy': This function or variable may be unsafe.
                 
                Consider using `strcpy_s` instead. To disable deprecation, 
                use `_CRT_SECURE_NO_WARNINGS`. See online help for details.
                

                strcpystrcpy_s 有什么区别?

                推荐答案

                strcpy 是一个不安全的函数.当您尝试使用 strcpy() 将字符串复制到不足以容纳它的缓冲区时,会导致缓冲区溢出.

                strcpy is a unsafe function. When you try to copy a string using strcpy() to a buffer which is not large enough to contain it, it will cause a buffer overflow.

                strcpy_s()strcpy()安全增强版.使用 strcpy_s,您可以指定目标缓冲区的大小,以避免复制期间缓冲区溢出.

                strcpy_s() is a security enhanced version of strcpy(). With strcpy_s you can specify the size of the destination buffer to avoid buffer overflows during copies.

                char tuna[5];  // a buffer which holds 5 chars incluing the null character.
                char salmon[] = "A string which is longer than 5 chars";
                
                strcpy( tuna, salmon ); // This will corrupt your memory because of the buffer overflow.
                
                strcpy_s( tuna, 5, salmon ); // strcpy_s will not write more than 5 chars.
                

                这篇关于“strcpy"和“strcpy_s"之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Consistent pseudo-random numbers across platforms(跨平台一致的伪随机数)
                Vary range of uniform_int_distribution(改变uniform_int_distribution的范围)
                What is a seed in terms of generating a random number?(就生成随机数而言,种子是什么?)
                Is 1.0 a valid output from std::generate_canonical?(1.0 是 std::generate_canonical 的有效输出吗?)
                Getting big random numbers in C/C++(在 C/C++ 中获取大随机数)
                What is the best way to generate random numbers in C++?(在 C++ 中生成随机数的最佳方法是什么?)
              1. <i id='eH260'><tr id='eH260'><dt id='eH260'><q id='eH260'><span id='eH260'><b id='eH260'><form id='eH260'><ins id='eH260'></ins><ul id='eH260'></ul><sub id='eH260'></sub></form><legend id='eH260'></legend><bdo id='eH260'><pre id='eH260'><center id='eH260'></center></pre></bdo></b><th id='eH260'></th></span></q></dt></tr></i><div id='eH260'><tfoot id='eH260'></tfoot><dl id='eH260'><fieldset id='eH260'></fieldset></dl></div>

                <small id='eH260'></small><noframes id='eH260'>

                    <legend id='eH260'><style id='eH260'><dir id='eH260'><q id='eH260'></q></dir></style></legend>
                      <bdo id='eH260'></bdo><ul id='eH260'></ul>

                          <tbody id='eH260'></tbody>

                          <tfoot id='eH260'></tfoot>