char *strcpy(char *s1, const char *s2)
将字符串s2复制到字符串数组s1中,返回s1的值
char *strncpy(char *s1, const char *s2, size_t n)
将字符串s2中最多n个字符复制到字符串数组s1中,返回s1的值
char *strcat(char *s1, const char *s2)
将字符串s2添加到字符串s1的后面。s2的第一个字符重定义s1的null终止符。返回s1的值
char *strncat(char *s1, const char *s2, size_t n)
将字符串s2中最多n个字符添加到字符串s1的后面。s2的第一个字符重定义s1的null终止符。返回s1的值
int strcmp(const char *s1, const char *s2)
比较字符串s1和字符串s2。函数在s1等于、小于或大于s2时分别返回0、小于0或者大于0的值
int strncmp(const char *s1, const char *s2, size_t n)
比较字符串s1中的n个字符和字符串s2。函数在s1等于、小于或大于s2时分别返回0、小于0或者大于0的值
char * strtok(char *s1,const char *s2)
用一系列strtok调用将s1字符串标记化(将字符串分成各个逻辑组件,如同一行文本中的每个单词),用字符串s2所包含的字符分隔。首次调用时包含s1为第一个参数,后面调用时继续标记化同一字符串,包含NULL为第一个参数。每次调用时返回当前标记指针。如果函数调用时不再有更多标记,则返回NULL
size_t strlen(const char *s)
确定字符串长度,返回null终止符之前的字符数
使用示例:
//源代码在Visual c++6.0环境下编译通过
#include
#include
int main()
{
char str1[50] = "Happy birthday to ", str2[] = "coffeehu";
char temp1[100],temp2[6], * temp;
char str[] = "This is a sentence with 7 tokens";
strcpy(temp1, str1);
strncpy(temp2, str1, 5);
temp2[5] = '\0';
cout << "strcpy result: " <
cout << "strncpy result: " << temp2 << "\n";
cout << "strcat result: " << strcat(str1, str2) << "\n";
cout << "strncat result: " << strncat(str1, str2, 6) <<"\n";
cout << "strcmp result: " << strcmp(temp2,"Happ") <<"\n";
cout << "strncmp result: " << strncmp(str1,"Happy",5) <<"\n";
//strtok function eg.
temp = strtok(str, " ");
while(temp != NULL)
{
cout << temp <<'\n';
temp = strtok(NULL, " ");
}
cout << "strlen result: " << strlen(str2) <<"\n";
return 0;
}