上一页 1 ··· 28 29 30 31 32 33 34 35 36 ··· 49 下一页
摘要: #include <iostream>using namespace std;int main(){ char ch1[10] = "ab"; char ch2[] = "abcdef"; strncat(ch1,ch2,3); //ababc 合并char类型的字符串,第三个参数是指需要合并的字符串个数 cout<<ch1<<endl; return 0;}//相对应的是string类的append成员函数的使用#include <iostream>#include <string>using 阅读全文
posted @ 2012-09-20 00:05 简单--生活 阅读(376) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>#include <string>using namespace std;int main(){ //char ch1[10] = "gh"; //char ch2[] = "abcdef"; //strncpy(ch1,ch2,6); //cout<<ch1<<endl; string str1="hello word"; //string str2="xianglingchuan"; //支持char字符串 //char st 阅读全文
posted @ 2012-09-20 00:05 简单--生活 阅读(230) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>#include <string>using namespace std;int main(){ //char ch1[] = "give ne"; //char ch2[] = "a cup"; //ch1 = ch2; 这样是错误的,你不能把一个数组名赋值给另一个数组名 //strcpy(ch1,ch2); //strcpy(ch1,"a cup");//第二个参数可能是常量字符数组 //第一: strcpy会将ch2中的所有字符,包括结束标志'\0'一 阅读全文
posted @ 2012-09-19 23:13 简单--生活 阅读(225) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>#include <string>using namespace std;int main(){ //char字符数组的的合并 char ch1[40] = "what's your name "; char ch2[] = "my name is jack"; strcat(ch1,ch2); cout<<"ch1:"<<ch1<<endl; cout<<"ch2:"<<ch2< 阅读全文
posted @ 2012-09-19 23:13 简单--生活 阅读(475) 评论(0) 推荐(0) 编辑
摘要: //char型字符串是C语言风格的字符串,它是用数组来保存字符串的,但是到了C++时代,由于延生了类,出现了一种C++风格的字符串,也就是string型字符串//这种风格的字符串是用string类来定义字符串的,因此要使用这个string类,我们必须在程序开头添加头文件string,string类存在于名字空间std中,这样我们就必须使用using std:string指令,或者直接用std::string来访问它//string类在定义时隐藏掉了字符串的数组性质,因此您有使用string类定义字会串时不用考虑如休将字符串存放在数组中,string类已经为您做好了这一步,您要做的,就是象定义一 阅读全文
posted @ 2012-09-19 23:12 简单--生活 阅读(245) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std;int main(){ //char man[12]; //cin.get(man,12); //cin.get的结束标志是"\n",也就是换行,因此遇到空格不会结束,而是把空格也看做一个空字符,同时在输入结束后,也就是用户输入一个回车后, //cin.get自动为当前接受输入的数组添加字符串结束标志'\0',因此它实际保存的有效字符是它的第二个参数减一,在本例中是(12-1)11个字符 //cout<<man<<endl; //但是与cin不同 阅读全文
posted @ 2012-09-19 23:11 简单--生活 阅读(528) 评论(0) 推荐(0) 编辑
摘要: //成员函数指针数组//假如我们将许多成员函数指针放在一个数组中,那么这个数组就叫成员函数指针数组//该数组中的成员函数指针可以通过数组的下标来进行调用,并且可以用成员函数的内存地址来对数组的各个成员函数指针进行初始化#include <iostream>#include <string>using namespace std;class Paper{public: void read(){ cout<<"纸上面的字可以读"<<endl;} void write(){ cout<<"纸可以用来写字&quo 阅读全文
posted @ 2012-09-17 23:58 简单--生活 阅读(472) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std;class Human{public: virtual void run()=0; virtual void eat()=0;};class Month:public Human{public: void run(){ cout<<"母亲跑百米要二十少"<<endl;} void eat(){ cout<<"母亲喜欢吃零食"<<endl;}};class Father:public Human{public: void 阅读全文
posted @ 2012-09-17 23:25 简单--生活 阅读(164) 评论(0) 推荐(0) 编辑
摘要: // 8 使用typedef简化函数指针的声明#include <iostream>using namespace std;//void (*p[5])(int&, int&);typedef void(*p)(float&,float&);//函数指针作为函数的参数的一般形式为:void func(void(*p)(int&,int&), int&, int&);//该函数func有三个参数,第一个参数void(*p)(int&,int&)是个函数指针,//它指向一个带有两个int型参数并且返回voi 阅读全文
posted @ 2012-09-17 00:04 简单--生活 阅读(485) 评论(0) 推荐(0) 编辑
摘要: //7 函数指针也可以作为函数的参数//既然指针可以作为函数的参数,那么指向某个函数的指针为什么就不可以呢?#include <iostream>using namespace std;void (*p[5])(int&, int&);//函数指针作为函数的参数的一般形式为:void func(void(*p)(int&,int&), int&, int&);//该函数func有三个参数,第一个参数void(*p)(int&,int&)是个函数指针,//它指向一个带有两个int型参数并且返回void值的函数,另外两个参 阅读全文
posted @ 2012-09-16 23:52 简单--生活 阅读(224) 评论(0) 推荐(0) 编辑
上一页 1 ··· 28 29 30 31 32 33 34 35 36 ··· 49 下一页
简单--生活(CSDN)