可能重复:
Why does MSVC++ consider “std::strcat” to be “unsafe”? (C++)为什么“strcat”被视为“不安全”?
这里是我的代码:
char sentence[ 100 ] = "";
char *article[ 5 ] = { "the", "a", "one", "some", "any" };
lexeme = rand() % 4; // random lexeme
strcat(sentence, article[ lexeme ]);
strcat(sentence, " ");
虽然MSVC调试++它给了我这些警告消息:
Warning 1 warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead.
Warning 2 warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead.
我该如何解决它?
+1推荐'std :: string',它总是* C++中这样的问题的正确答案。 – 2011-04-26 16:54:10
我认为strncat是一个完全合理的方法来做到这一点,特别是因为他在这个例子中使用C字符串。 – 2011-04-26 16:58:22
@最大,是的,这将是一个很好的替代响应。我只是喜欢在C++代码中避免使用CRT,原因就像上面的问题。 – 2011-04-26 16:59:56