可能重複:
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