theEagles

I am sailing, to be with you, to be free.
posts - 11, comments - 0, trackbacks - 0, articles - 4
  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

公告

2012年5月11日

一些人制造垃圾代码,其他的人为这些垃圾代码埋单。

posted @ 2012-05-11 11:54 theEagles 阅读(4) 评论(0) 编辑

2012年4月23日

 

//===============================================
// string  ------>  number
//===============================================
//int atoi ( const char * str );
//__int64 atoi ( const char * str );
//long int atol ( const char * str );
//double atof ( const char * str );
//double strtod ( const char * str, char ** endptr );
//unsigned long strtoul(const char *nptr,char **endptr, int base );
atoi();     _wtoi(),    _ttoi();   
atol();     _wtol();    _tstol();
strtol();   wcstol();   _tcstol();
strtoul();  wcstoul();  _tcstoul();
_atoi64();  _wtoi64(),  _ttoi64();
atof(),     _wtof();    _tstof();
strtod();   wcstod();   _tcstod();


//===============================================
// number  ------>  string
//===============================================
//char *  itoa ( int value, char * str, int base );
itoa(),   _itow(),      _itot();
itoa_s(), _itow_s(),    _itot_s();
ltoa();   _ltow();      _ltot();
ltoa_s(); _ltow_s();    _ltot_s();
ultoa(),  _ultow(),     _ultot();
ultoa_s(), _ultow_s(),  _ultot_s();





//int wctomb ( char * pmb, wchar_t character )
//size_t wcstombs ( char * mbstr, const wchar_t * wcstr, size_t max );
//size_t mbstowcs ( wchar_t * wcstr, const char * mbstr, size_t max );
//template <size_t size>
//errno_t wcstombs_s(size_t *pReturnValue, char (&mbstr)[size],const wchar_t *wcstr,size_t count ); // C++ only
//return Zero if successful, an error code on failure.
//error code: 
//
//EINVAL  mbstr is NULL and sizeInBytes > 0 
//EINVAL  wcstr is NULL
//ERANGE  The destination buffer is too small to contain the converted string 
//        (unless count is _TRUNCATE; see Remarks below)      
wctomb();   mbtowc();
wcstombs(); wcstombs_s(); 
mbstowcs(); mbstowcs_s();


// 
div_t res = div(5,2);
ASSERT(div(5,2).quot==2);
ASSERT(div(5,2).rem ==1);

posted @ 2012-04-23 10:09 theEagles 阅读(9) 评论(0) 编辑

2012年3月14日

CArchive:: << CString 会先写入字符串的长度,再写入字符串。

如果是Unicode字符串,写每个CString 之前都会先写入编码"FF FE”,再写入字符串长度值,最后写入字符串。

写入的字符串长度值是经过编码后的值,添加了一些冗余,目的是为了自解释性。

因此,如果用<<把CSting写入了文件,读取时也必须用>>才能正确地把它读出来。

 

CArchive::WriteString(LPCTSTR) 用来写一行文本,因此写完纯文本后需要写入一个\n。

CArchive::ReadString(LPCTSTR) 和WriteString配对,用来读一行文本,读取的时候字符\n会丢掉。

posted @ 2012-03-14 19:54 theEagles 阅读(32) 评论(0) 编辑

2012年2月29日

 

1) What to do: 加载资源图标到CImageList:

2) How to do:

CBitmap bmp;
bmp.LoadBitmap(IDB_GRAPH16x16);
UINT nFlags = ILC_MASK;
nFlags |= (theApp.m_bHiColorIcons) ? ILC_COLOR24 : ILC_COLOR4;
m_ImageList.DeleteImageList(); //清空ImageList
m_FileViewImages.Create(16, 16, nFlags, 0, 0); //创建ImageList 指定宽高和风格
m_ImageList.Add(&bmp); // 加载图标到ImageList
这里已知图标的宽度和高度是16x16.

否则需要先根据CBitmap对象创建一个BITMAP对象,调用BITMAP的成员得到高度:

(无法根据CBitmap的成员GetBitmapDimension()得到宽高,返回宽高居然都是0,不知道微软是怎么设计这个类的。。。)

BITMAP bmpObj;
bmp.GetBitmap(&bmpObj);
int cx=bmpObj.bmWidth;
int cy= bmpObj.bmHeight;

posted @ 2012-02-29 12:42 theEagles 阅读(36) 评论(0) 编辑

2012年2月21日

Mutable 关键词的作用是:可以在常函数中被修改其值。

Mutable适用的场合极少,因此当你觉得你需要使用该关键词时,请再三思考!

下面列出几种Mutable适用的场合:

1. You have a constant object, but for debugging purposes want to track how often a constant method is called on it. Logically you're not changing the object. Note that if you're making decisions in your program based on a mutable variable, you've almost certainly violated logical constness and need to rethink things.

class Employee {
public:
Employee(const std::string & name)
: _name(name), _access_count(0) { }
void set_name(const std::string & name) {
_name = name;
}
std::string get_name() const {
_access_count++;
return _name;
}
int get_access_count() const { return _access_count; }

private:
std::string _name;
mutable int _access_count;
}



2. As a more complex example, you might want to cache the results of an expensive operation:

class MathObject {
public:
MathObject() : pi_cached(false) { }
double pi() const {
if( ! pi_cached ) {
/* This is an insanely slow way to calculate pi. */
pi = 4;
for(long step = 3; step < 1000000000; step += 4) {
pi += ((-4.0/(double)step) + (4.0/((double)step+2)));
}
pi_cached = true;
}
return pi;
}
private:
mutable bool pi_cached;
mutable double pi;
};

Now we don't calculate pi until someone asks for it, but when they do we cache the result, which is good because we're calculating it in a really slow and stupid way. Logically the function is still const (pi isn't about to change).

Ultimately you almost certainly do not need mutable at any given moment. I've gone years between wanting the mutable keyword. If you think you need mutable, think twice. Be sure that the object will still be logically constant, even as its internals change.


链接:http://www.highprogrammer.com/alan/rants/mutable.html


posted @ 2012-02-21 01:17 theEagles 阅读(25) 评论(0) 编辑

2012年2月20日

摘要: 如题~~~阅读全文

posted @ 2012-02-20 23:45 theEagles 阅读(5) 评论(0) 编辑

摘要: 如题~~阅读全文

posted @ 2012-02-20 23:44 theEagles 阅读(4) 评论(0) 编辑

摘要: 普遍的情况~阅读全文

posted @ 2012-02-20 23:43 theEagles 阅读(2) 评论(0) 编辑

摘要: 如题...阅读全文

posted @ 2012-02-20 23:40 theEagles 阅读(5) 评论(0) 编辑

摘要: 如题...阅读全文

posted @ 2012-02-20 23:40 theEagles 阅读(5) 评论(0) 编辑