1.字符串常用方法
//Test.cpp #include#include using namespace std; int main() { char* str ="Hello,world"; char* str1 = "Hello,world"; cout<< str < 2.只在C文件中可正常运行的方法
#include#include int main(void){ char *str1="www.dotcpp.com"; char *str2="WWW.DOTCPP.COM"; int p=strnicmp(str2,str1,3); //比较字符串str2和str1的前3个字符但不区分大小写 if(p>0){ printf("str2 is greater than str1n"); }else if(p<0){ printf("str2 is less than str1n"); }else{ printf("str2 is equals str1n"); } return 0; }
遇到的坑1.在cpp文件中使用strnicmp做字符串比较时总是报以下错误,当把cpp文件改为.c文件时就可以正常运行了:



