欢迎来到天天文库
浏览记录
ID:37915361
大小:59.50 KB
页数:5页
时间:2019-06-02
《CC++常用函数》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、C/C++常用函数分类:C/C++基础2010-03-1400:22465人阅读评论(0)收藏举报 Strstr strncpy strcpy_s//VC6.0没有此函数 strcpy CString转换string CString转换char数组 String转换double Char*转换string Int转换string String转换char[] atolConvertstringtolonginteger(function)strtoulConvertstringtounsignedlon
2、ginteger(function)strtodConvertstringtodouble(function)atoiConvertstringtointeger(function)atofConvertstringtodouble(function)strtolConvertstringtolonginteger(function) /*****************strstrexample******************/#includeusingnamespacestd;
3、 intmain(){charstr[]="Thisisaimplestring";char*pch;pch=strstr(str,"s");//pch没有开辟新的地址,还是指向str的地址空间,次例输出可以说明问题strncpy(pch,"sample",6);puts(str);strcpy(st,pch);cout<<*pch<4、[1]=50; b=strstr("@@![#$",a);return0;} /**********************strncpyexample***************************/#include#includeintmain(){charstr1[]="Tobeornottobe";charstr2[6];strncpy(str2,str1,5);//将str1前五个字符复值给str2str2[5]='/0';puts(str2);ret5、urn0;} /************************strcpy_s(VC6.0没有此函数)和strcpy()****************************/strcpy_s和strcpy()函数的功能应该一样的。strcpy函数,就象gets函数一样,它没有方法来保证有效的缓冲区尺寸,所以它只能假定缓冲足够大来容纳要拷贝的字符串。在程序运行时,这将导致不可预料的行为。用strcpy_s就可以避免这些不可预料的行为。这个函数用两个参数、三个参数都可以,只要可以保证缓冲区大小。三个参6、数时:errno_tstrcpy_s(char*strDestination,size_tnumberOfElements,constchar*strSource);两个参数时:errno_tstrcpy_s(char(&strDestination)[size],constchar*strSource);//C++only #include#includeusingnamespacestd; voidmain(){char*str1=NULL;str1=newchar7、[20];charstr[7];strcpy_s(str1,20,"helloworld");//三个参数strcpy_s(str,"hello");//两个参数但如果:char*str=newchar[7];会出错:提示不支持两个参数cout<<"strlen(str1)"<8、str;GetDlgItem(IDC_EDIT1)->GetWindowText(str);info.account=str.GetBuffer(0);str.ReleaseBuffer(); 2.CString转换char数组char*p;charc[10];p=str.GetBuffer(str.GetLength());str.ReleaseBuffer();strcpy(c,p); 3.stringtodouble10
4、[1]=50; b=strstr("@@![#$",a);return0;} /**********************strncpyexample***************************/#include#includeintmain(){charstr1[]="Tobeornottobe";charstr2[6];strncpy(str2,str1,5);//将str1前五个字符复值给str2str2[5]='/0';puts(str2);ret
5、urn0;} /************************strcpy_s(VC6.0没有此函数)和strcpy()****************************/strcpy_s和strcpy()函数的功能应该一样的。strcpy函数,就象gets函数一样,它没有方法来保证有效的缓冲区尺寸,所以它只能假定缓冲足够大来容纳要拷贝的字符串。在程序运行时,这将导致不可预料的行为。用strcpy_s就可以避免这些不可预料的行为。这个函数用两个参数、三个参数都可以,只要可以保证缓冲区大小。三个参
6、数时:errno_tstrcpy_s(char*strDestination,size_tnumberOfElements,constchar*strSource);两个参数时:errno_tstrcpy_s(char(&strDestination)[size],constchar*strSource);//C++only #include#includeusingnamespacestd; voidmain(){char*str1=NULL;str1=newchar
7、[20];charstr[7];strcpy_s(str1,20,"helloworld");//三个参数strcpy_s(str,"hello");//两个参数但如果:char*str=newchar[7];会出错:提示不支持两个参数cout<<"strlen(str1)"<8、str;GetDlgItem(IDC_EDIT1)->GetWindowText(str);info.account=str.GetBuffer(0);str.ReleaseBuffer(); 2.CString转换char数组char*p;charc[10];p=str.GetBuffer(str.GetLength());str.ReleaseBuffer();strcpy(c,p); 3.stringtodouble10
8、str;GetDlgItem(IDC_EDIT1)->GetWindowText(str);info.account=str.GetBuffer(0);str.ReleaseBuffer(); 2.CString转换char数组char*p;charc[10];p=str.GetBuffer(str.GetLength());str.ReleaseBuffer();strcpy(c,p); 3.stringtodouble10
此文档下载收益归作者所有