C++
文章平均质量分 77
tongjm624
这个作者很懒,什么都没留下…
展开
-
CString,int,string,char*之间的转换
《C++标准函数库》中说的 有三个函数可以将字符串的内容转换为字符数组和C—string 1.data(),返回没有”\0“的字符串数组 2,c_str(),返回有”\0“的字符串数组 3,copy() ................................................................. int 转 CString: C...原创 2009-09-17 09:02:04 · 49 阅读 · 0 评论 -
c++ string 类基本用法样例
#include // 使用 string 类时须包含这个文件 #include using namespace std; int main() { string str1; // 输入与输出 cout str1; getchar(); cout2009-09-07 14:20:09 · 91 阅读 · 0 评论 -
C++ 类中的静态变量和静态成员函数
静态数据成员: 下面看一个例子: #include class Point { public: void output() { } static void init() { } }; void main( void ) { Point pt; pt.init(); pt.output(); } 这样编译是不会有任何错误的。 下面这样看 #incl...原创 2009-08-13 10:49:25 · 63 阅读 · 0 评论 -
C++友元类------自己的不一定正确
/*预引用.告诉编译器类B将会在后面定义.使用了预引用后,就可以声明未定义的类的友元、指针和引用。但是不可以使用那些需要知道预引用的类的定义细节的语句,如声明该类的一个实例或者任何对该类成员的引用。*/ class B; /*注明见上*/ class A { public: firend B; }; class B { }; 若不使用预引用.则声明友元时必须加...2009-08-13 10:03:20 · 137 阅读 · 0 评论 -
友元函数初步理解
[b]友元函数:[/b] [color=red]友元函数-----不是类的成员函数,但却能访问类的数据成员。[/color] [color=red]定义[/color]: friend Student &visit(Student &stu,char *name,char newsex); [color=red]实现[/color]: Student &visit(Student &st...2009-08-12 16:18:47 · 80 阅读 · 0 评论 -
关于this指针
[b]this指针[/b] 1.只能用在类的成员函数中,它指向掉用这个函数的对象。 2.返回对象本身。 3.为了区分形参和数据成员。 4.静态成员函数不能使用this指针。...2009-08-12 11:02:13 · 124 阅读 · 0 评论 -
C++学习重点分析
一、#include “filename.h”和#include 的区别 #include “filename.h”是指编译器将从当前工作目录上开始查找此文件 #include 是指编译器将从标准库目录中开始查找此文件 二、头文件的作用 加强安全检测 通过头文件可能方便地调用库功能,而不必关心其实现方式 三、* ...原创 2009-11-17 18:22:02 · 81 阅读 · 0 评论 -
C++/C编程指南-- 第5章 常量
第5章 常量 常量是一种标识符,它的值在运行期间恒定不变。C语言用 #define来定义常量(称为宏常量)。C++ 语言除了 #define外还可以用const来定义常量(称为const常量)。 5.1 为什么需要常量 如果不使用常量,直接在程序中填写数字或字符串,将会有什么麻烦? (1) 程序的可读性(可理解性)变差。程序员...原创 2009-10-29 08:53:15 · 94 阅读 · 0 评论 -
C++ MAP 基本用法
/* map内部数据的组织,map内部自建一颗红黑树(一种非严格意义上的平衡二叉树),这颗树具有对数据自动排序的功能, 所以在map内部所有的数据都是有序的。 */ #include #include using namespace std; typedef map mapStudent; typedef map::iterator mapStudengIt...2009-10-20 16:13:29 · 89 阅读 · 0 评论 -
C++ LIst 基本用法
#include #include using namespace std; typedef list LISTINT; void display(LISTINT list,char *name) { LISTINT::iterator i; cout2009-10-20 10:21:45 · 137 阅读 · 0 评论 -
stringstream的用法
stringstream通常是用来做数据转换的。相比c库的转换,它更加安全,自动和直接。 例子一:基本数据类型转换例子 int转string #include #include #include int main() { std::stringstream stream; std::string result; int i =...原创 2009-10-19 08:49:30 · 148 阅读 · 0 评论 -
C++ 内联inline函数
内联inline函数 在C中保持效率的一种方法是使用宏,他的行为类似于函数调用但却没有调用的开销(like a function call without the normal function call overhead.)。 宏是由由预处理器preprocessor而非编译器compiler处理的,其直接替换宏代码,没有参数入栈、函数调用及返回等开销。 ...原创 2009-10-16 09:18:35 · 135 阅读 · 0 评论 -
string类的部分操作
#include #include using std::cin; //using?ü??????éù?÷£??ùDè??×?cinê??ú?ü??????std?D?¨ò?μ??£ using std::cout; using std::endl; using std::string; int main() { string str1; //...2009-09-10 13:48:48 · 123 阅读 · 0 评论