Category Archives: C/C++

gcc的基本使用

1、gcc的编译过程 ( 参数分别为:E S c , 输出文件参数-o )

  • 预处理:.c —> .i C文件,头文件展开、宏替换、去注释
    gcc -E sum.c -o sum.i// 将sum.c预处理生成sum.i文件
  • 编译器:.i —> .s 汇编文件,C语言代码变成汇编代码
    gcc[......]

    继续阅读

自定义字符串类String,实现运算符重载,内存管理

1、String.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#pragma once
#include <iostream>
using namespace std;
 
class String {
	friend ostream &operator << (ostream &, String &);
private:
	char *m_name = NULL;
	char *setM_name(const char *cstring);
	char *strAppend(const char *, const char *);
public:
	String(const char *cstring = "");
	String(const String &);
	~String();
	bool operator == (String &string);
	String &operator = (String &string);
	String &operator = (const char *cstring);
	String operator + (const char *cstring);
	String operator + (const String &string);
	String &operator += (const char *cstring);
	String &operator += (const String &string);
	char operator[](int index);
	bool operator<(const String &string);
};
 
ostream &operator << (ostream &cout, String &string);
</iostream>

2、String.cpp

[……]

继续阅读