摘要: // 11 string字符串的比较#include <iostream>#include <string>using namespace std;int main(){ string s1 = "155"; string s2 = "52"; char c[] = "34"; int i, j, k, l, m, n; i = s1.compare(s2); //compare比较的事字符而不是数字 //compare 将s1与s2比较,返回0为相等,1为s1大于s2,-1为s1小于s2; cout<& 阅读全文
posted @ 2012-09-23 15:48 简单--生活 阅读(358) 评论(0) 推荐(0) 编辑
摘要: // 9 string类的erase成员函数的使用/*#include <iostream>#include <string>using namespace std;int main(){ string s = "give me"; cout<<"原始字符串为:"<<s<<endl; s.erase(1,3); //炎1开始删除三个字符 cout<<"原始字符串为:"<<s<<endl; s.erase(2); //删除二个字符,从后面开始 阅读全文
posted @ 2012-09-23 15:47 简单--生活 阅读(257) 评论(0) 推荐(0) 编辑
摘要: // 10string 型字符串的查找/*#include <iostream>using namespace std;int main(){ char ch1[20]; char *p, c='w'; strcpy(ch1,"hellwo wordlxxdxxd"); p = strchr(ch1,c); //在字符串中查找字符 if(p){ //这里的p-ch1, 相当于p在ch1中的位置 //这里的p是指的从查找到字符后面的所有字符, //这里的位置有点不清楚样 //还要提高 //由于一个字符占一个字节,因此用p-ch1就是用求出p相对于c 阅读全文
posted @ 2012-09-23 15:47 简单--生活 阅读(694) 评论(0) 推荐(0) 编辑
摘要: // 7 string型字符串的拷贝/*#include <iostream>#include <string>using namespace std;int main(){ //char ch1[15] = "hello word"; //char ch2[] = "xiang ling chuan"; //cout<<"源字符串"<<ch1<<endl; //memmove(ch1,ch2,5); //cout<<"拷贝后:"<< 阅读全文
posted @ 2012-09-23 15:44 简单--生活 阅读(451) 评论(0) 推荐(0) 编辑
摘要: //8 string类insert成员函数的使用/*#include <iostream>#include <string>using namespace std;int main(){ string str1 ="php china"; string str2 = "hello word"; str1.insert(4,str2,0,5); cout<<str1<<endl; return 0;}*/ 阅读全文
posted @ 2012-09-23 15:44 简单--生活 阅读(822) 评论(0) 推荐(0) 编辑
简单--生活(CSDN)