atoi(p) 字符串转换到 int 整型
atof(p) 字符串转换到 double 符点数
atol(p) 字符串转换到 long 整型
3)字符检查
isalpha() 检查是否为字母字符
isupper() 检查是否为大写字母字符
islower() 检查是否为小写字母字符
isdigit() 检查是否为数字
isxdigit() 检查是否为十六进制数字表示的有效字符
isspace() 检查是否为空格类型字符
iscntrl() 检查是否为控制字符
ispunct() 检查是否为标点符号
isalnum() 检查是否为字母和数字
isprint() 检查是否是可打印字符
isgraph() 检查是否是图形字符,等效于 isalnum() | ispunct()
4)函数原型
原型:strcpy(char destination[], const char source[]);
功能:将字符串source拷贝到字符串destination中
例程:
#include <iostream.h>
#include <string.h>
void main(void)
{
char str1[10] = { "TsinghuaOK"};
char str2[10] = { "Computer"};
cout <<strcpy(str1,str2)<<endl;
}
运行结果是:Computer
第二个字符串将覆盖掉第一个字符串的所有内容!
注意:在定义数组时,字符数组1的字符串长度必须大于或等于字符串2的字符串长度。不能用赋值语句将一个字符串常量或字符数组直接赋给一个字符数组。所有字符串处理函数都包含在头文件string.h中。
strncpy(char destination[], const char source[], int numchars);
strncpy:将字符串source中前numchars个字符拷贝到字符串destination中。
strncpy函数应用举例
原型:strncpy(char destination[], const char source[], int numchars);
功能:将字符串source中前numchars个字符拷贝到字符串destination中
例程:
#include <iostream.h>
#include <string.h>
void main(void)
{
char str1[10] = { "Tsinghua "};
char str2[10] = { "Computer"};
cout <<strncpy(str1,str2,3)<<endl;
}
运行结果:Comnghua
注意:字符串source中前numchars个字符将覆盖掉字符串destination中前numchars个字符!
原型:strcat(char target[], const char source[]);
功能:将字符串source接到字符串target的后面
例程:
#include <iostream.h>
#include <string.h>
void main(void)
{
char str1[] = { "Tsinghua "};
char str2[] = { "Computer"};
cout <<strcpy(str1,str2)<<endl;
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-34103-9.html
因为真货里本来就有质检合格证嘛~对不对
萨达姆是民选合法总统