January 13th Tuesday 2009 (一月 十三日 火曜日)

   These days we have to work until 9 o'clock at night.  Two of our team began to learn how to implement a user interface
in Java.  Today I have to check and learn the code written by them.

  The winter still remains.  The Spring Festival is coming, it also bring us more fatigues.  After fight all day and all
night, we did not get a rest before the festival.

  Why I can choose the tried and poor vocation?

//fr.cpp
#include <unistd.h>
#include <string.h>
#include <iostream>

using namespace std;

#define MSTRING_MAX 256

class MString {
private:
        char *buf;

public:
        MString() {
                buf = new char[MSTRING_MAX];
                memset(buf, 0, sizeof(buf));
        }

        MString(char *str, int str_len) {
                buf = new char[MSTRING_MAX];
                memset(buf, 0, sizeof(buf));
                strncpy(buf, str, str_len);
        }
        ~MString() { delete buf; }

        char * getChars() { return buf; }

        friend int operator>(const MString& str1, const MString& str2);
};

int operator> (const MString& str1, const MString& str2) {
        return (strcmp(str1.buf, str2.buf) > 0) ? 1 : 0;
}

int main() {
        MString mstr1("abc", 3);
        MString mstr2("luming", 6);

        cout<<mstr1.getChars()<<endl;
        cout<<mstr2.getChars()<<endl;
        cout<<(mstr1>mstr2)<<endl;

        sleep(10000);

        return 0;
}

//const_cast<> example
const char *klingongreeting = "hello";

size_t length = strlen(const_cast<char*>(klingongreeting));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值