
c++
TOliverQueen
人生若只如初见
展开
-
C++文件读取
#include<stdio.h>#include<stdlib.h>int main() { char* filename = "G:\\test.txt"; FILE* fp = fopen(filename, "rb"); if (fp == NULL) { printf("no such file"); return -1; } //读数据...原创 2018-12-03 10:57:45 · 174 阅读 · 0 评论 -
C++类实现面向对象
#include "DataStore.h"#include<stdlib.h>#include<stdio.h>DataStore::DataStore() { m_head.next = NULL;}DataStore::~DataStore() { Student* p = m_head.next; while (p) { Student* ...原创 2018-12-11 16:40:11 · 233 阅读 · 0 评论 -
C++ 模板之string
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<string>using namespace std;void test(const string& t) {}void test(string& t) {}int main(){ s...原创 2018-12-13 22:27:04 · 455 阅读 · 0 评论 -
C++模板库list
#include<stdio.h>#include<list>using namespace std;int main(){ list<int> mylist(4); mylist.clear(); mylist.push_back(1); mylist.push_back(2); mylist.push_back(3); mylist.p...原创 2018-12-13 21:21:55 · 434 阅读 · 0 评论 -
C++vector的使用
#include<stdio.h>#include<stdlib.h>#include<vector>using namespace std;int main(){ vector<int> arr(2); arr.clear(); arr.push_back(12); arr.push_back(13);// int capa...原创 2018-12-13 20:24:27 · 165 阅读 · 0 评论 -
C++实现模板实现动态申请内存
#include<stdio.h>#include<stdlib.h>#include<string.h>template <typename T>class Array{private: T* m_buffer; int m_capacity; int m_size;public: Array(int capacity=4)...原创 2018-12-13 17:16:43 · 806 阅读 · 0 评论 -
C++模板实现
#include<stdio.h>#include<stdlib.h>template <typename T>T find_max(T data[],int len){ T max = data[0]; for (int i = 0; i < len; i++) { if (data[i] > max) max = dat...原创 2018-12-13 16:17:01 · 314 阅读 · 0 评论 -
C++重载输出操作符
#include<stdio.h>#include<stdlib.h>class Point{public: int x; int y;public: Point() { } Point(int a, int b) { x = a; y = b; }};class Logger{public: Logger() { } Lo...原创 2018-12-13 11:27:28 · 766 阅读 · 0 评论 -
C++重载类型转换操作符()
#include<stdio.h>#include<stdlib.h>class Fraction{public: int num; int den; Fraction():num(1),den(1) { } Fraction(int n, int d) :num(n), den(d) { } operator double() { ret...原创 2018-12-13 11:06:47 · 393 阅读 · 0 评论 -
C++重载关系运算符==,
#include<stdio.h>#include<stdlib.h>class Fraction{public: int num; int den; Fraction():num(1),den(1) { } Fraction(int n,int d):num(n),den(d) { } bool operator ==(const Fracti...原创 2018-12-13 10:47:38 · 1535 阅读 · 0 评论 -
C++结构体在文件中的存取
#include<stdio.h>#include<stdlib.h>#include<string.h>char* file_name = "G:\\aaaa.xyz";struct Car { char maker[32]; int price;};struct owner { char name[32]; int age; Car*...原创 2018-12-03 17:33:46 · 2446 阅读 · 0 评论 -
C++重载【】
#include<stdio.h>#include<string.h>class Text{public: int m_size; char* m_buf; Text(const char* str) { m_size = strlen(str) + 1; m_buf = new char[m_size]; strcpy(m_buf, str...原创 2018-12-12 22:49:40 · 1495 阅读 · 0 评论 -
C++实现重载操作运算符
#include<stdio.h>#include<stdlib.h>class Fraction{public: int num; //分子 int den; //分母 Fraction() : num(1), den(1) { } Fraction(int n, int d) : num(n), den(d) { } //重载加号操作符 ...原创 2018-12-12 22:08:27 · 207 阅读 · 0 评论 -
C++实现朋友类
#include<stdio.h>#include<stdlib.h>#include<string.h>class Object{ friend void Print(Object* p); friend class Something;public: Object(int v):value(v) { }private: int v...原创 2018-12-12 21:42:40 · 354 阅读 · 0 评论 -
C++实现拷贝构造函数
#include<stdio.h>class Object {public: int a; int b;public: Object(int a,int b) { this->a = a; this->b = b; } Object(const Object& other) { this->a = other.a; th...原创 2018-12-12 21:16:53 · 193 阅读 · 0 评论 -
C++实现字段分割
#include<stdlib.h>#include<string.h>#include<stdio.h>void show(char* text);int split(char* string, char* arg[]);void show(char* text) { char* argv[128]; int tem_count = spli...原创 2018-12-12 20:10:05 · 228 阅读 · 0 评论 -
C++纯虚函数实现命令行解析
CmdInput.cpp#include <stdio.h>#include <string.h>#include "CmdInput.h"CmdInput::CmdInput(){ m_handler = NULL;}void CmdInput::SetHandler(CmdHandler* h){ m_handler = h;}int...原创 2018-12-12 16:36:11 · 171 阅读 · 0 评论 -
C++结构体实现面向对象
#include <stdio.h>#include <string.h>#include <stdlib.h>#include "DataStore.h"DataStore* ds_create(){ // 动态创建对象 DataStore* store = (DataStore*)malloc(sizeof(DataStore));...原创 2018-12-11 16:42:35 · 438 阅读 · 0 评论