Strict null-terminated sequence utilities
Some of the standard C++ library include files have been edited to use replacement overloads for some common C library functions (if available), with the goal of improving const-correctness: functions passed aconst char* return const char*.The table below shows the functions and files that have been changed.
| Header | Functions |
|---|---|
| <cstring> | strchr, strpbrk, strrchr, strstr, memchr |
| <cwchar> | wcschr wcspbrk, wcsrchr, wcsstr, wmemchr |
#include <cstring> const char* str1; char* str2 = strchr(str1, 'a');Gives the following compiler error:
error: invalid conversion from ‘const char*’ to ‘char*’Fixing this is easy, as demonstrated below.
#include <cstring> const char* str1; const char* str2 = strchr(str1, 'a');More information about the C++ standard requirements can be found in chapter 21, section "Null-terminated sequence utilities."
链接:https://gcc.gnu.org/gcc-4.4/porting_to.html
=====
原来是C++的标准库头文件有变化,目标是“improving const-correctness”,其中就有strstr这个函数。好吧,在原来的代码修改了加了强制转化就ok了。
没有评论:
发表评论