05_03.cpp
来自「一些C++的课件和实验源代码」· C++ 代码 · 共 40 行
CPP
40 行
// 05_03.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
class Text {
char* pContent;
public:
Text() { pContent = NULL; } // 构造函数,初始化成员
~Text() { // 析构函数,释放资源
if (pContent != NULL) delete pContent;
}
void SetContent(char* str) { // 设置文本内容
strcpy(pContent, str);
}
void GetBuffer(int len) { // 重新分配存储空间
pContent = new char[len];
strcpy(pContent, "");
}
void Print() { cout << pContent << endl; } // 输出文本
};
int main(int argc, char* argv[])
{
Text t;
t.GetBuffer(10);
t.SetContent("Hello");
// ...
t.SetContent("Hello World!");
t.Print();
getch();
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?