力为的技术博客

联系 聚合 管理
  154 Posts :: 1 Stories :: 561 Comments :: 0 Trackbacks

4. C++ FAQ

posted @ 2017-11-15 19:07 力为 阅读(580) | 评论 (0)  编辑

posted @ 2015-11-03 16:43 力为 阅读(3634) | 评论 (0)  编辑

posted @ 2015-08-07 13:42 力为 阅读(1407) | 评论 (0)  编辑

posted @ 2015-01-13 14:24 力为 阅读(1998) | 评论 (1)  编辑

posted @ 2015-01-06 16:43 力为 阅读(1914) | 评论 (0)  编辑

posted @ 2014-08-24 18:50 力为 阅读(2709) | 评论 (1)  编辑

     摘要: 获取程序所在的目录是一个常用的需求,在Windows下使用GetModuleFileName可以满足需求。
在使用Qt,wxWidgets等实现可跨平台代码该如何处理?
---找与GetModuleFileName等价的API。这是我马上能相到的。很遗憾,却没有找到。

有时候,你需要的东西就在你的面前,你却找不到它。  阅读全文
posted @ 2013-04-16 13:46 力为 阅读(2607) | 评论 (3)  编辑

posted @ 2013-01-23 23:26 力为 阅读(2096) | 评论 (1)  编辑

     摘要: std::list提供了两个排序方法:std::list::sort() 和std::list::sort(_Pr3 _Pred)。
std::list::sort(_Pr3 _Pred)需要提供一个函数对象(仿函数)作为参数。构造函数有多种方式,lambda表达式算是最复合潮流的一种。  阅读全文
posted @ 2013-01-20 13:50 力为 阅读(5543) | 评论 (2)  编辑

     摘要: 有人说,MS引入_UNICODE就是个错误,STL引入wstring也是个错误;而鼓励使用UTF8 string做为程序内部string存储格式。在与GUI交互的时候,转换为wstring(假定GUI使用的是_UNICODE)。这样做至少有一个好处:相对的可以减少程序运行时占用内存的大小。当然现在内存资源也不是个什么大问题,我更关心的是保存/读取XML数据的效率。  阅读全文
posted @ 2012-10-29 14:53 力为 阅读(14300) | 评论 (2)  编辑

posted @ 2012-10-06 12:21 力为 阅读(2005) | 评论 (2)  编辑

     摘要: 扔掉MultiByteToWideChar 吧,使用std::wstring_convert和 std::codecvt_utf8 来处理UTF8与WChar之间的互转。
VC和Clang都支持哦~  阅读全文
posted @ 2012-09-11 17:59 力为 阅读(18593) | 评论 (9)  编辑

     摘要: 手动建立工程,配置Qt环境,运行debug版本时,弹出一个错误对话框:
must construct a qapplication before a qpaintdevice  阅读全文
posted @ 2012-09-07 15:31 力为 阅读(1884) | 评论 (0)  编辑

     摘要: 控制流输出格式:固定宽度右对齐,精度  阅读全文
posted @ 2012-08-26 11:22 力为 阅读(494) | 评论 (0)  编辑

     摘要: 最近打算把项目做成跨平台的,使之能够在Mac上运行。做为XCode的默认编译器,据说Clang的编译速度很快,所以决定第一步就需要玩起Clang来。
在编译的过程中遇到不少问题,整理了如下几点:
  阅读全文
posted @ 2012-07-22 17:40 力为 阅读(1925) | 评论 (3)  编辑

     摘要: 一个布尔变量,无论是成员变量还是全局局部变量,加入定义的时候未初始化,其值是true 还是 false?  阅读全文
posted @ 2011-04-16 22:39 力为 阅读(3152) | 评论 (2)  编辑

     摘要: 设想这样一种情形:
有个模块需要封装给其他用户使用,接口中需要处理字符串类型。

那么采用std::string或者std::wstring是否合适呢?

  阅读全文
posted @ 2011-04-02 14:18 力为 阅读(2533) | 评论 (2)  编辑

     摘要: 一般情况下,没人会写这样的程序。返回临时对象的引用时候,编译器也会有warning。假如,忽略了warning,就有可能发生杯具。  阅读全文
posted @ 2011-04-01 18:09 力为 阅读(2766) | 评论 (11)  编辑

     摘要: 结论:
如果知道vector的大小,resize一下可以当数组来用,不会分配多余的内存。  阅读全文
posted @ 2011-03-17 20:18 力为 阅读(3709) | 评论 (1)  编辑

posted @ 2010-04-13 13:14 力为 阅读(696) | 评论 (1)  编辑

     摘要: 递归可以方便直观的实现算法,但有时候却会大大的影响程序性能,甚至引发程序非正常死亡。  阅读全文
posted @ 2010-03-24 14:24 力为 阅读(2758) | 评论 (3)  编辑

     摘要: 二十一世纪的第一个十年过去了,回顾了一下这些年写的博客,发现自己也没闲着。但不免也有些遗憾,内容大都是关于知识、经验和技术,而关于思考和idea的却比较少。期待下一个十年吧!
第一篇日志是在2004年发布在CSDN的博客上(记得开始不叫博客),截至到现在累积了不少东西了。为了怀念这过去的十年(2000~2003是个空白期,那段时间国内好像也没博客,网络也不发达,信息也闭塞),特整理了一下,称作我的原创技术随笔大全(2000~2009)  阅读全文
posted @ 2010-01-09 01:13 力为 阅读(4261) | 评论 (4)  编辑

     摘要: 变量名不要使用near
  阅读全文
posted @ 2009-03-03 22:38 力为 阅读(683) | 评论 (0)  编辑

     摘要: 在libcpmt.lib声明过的operator new在nafxcw.lib中再次定义  阅读全文
posted @ 2009-03-01 02:58 力为 阅读(1238) | 评论 (0)  编辑

     摘要: 瞧,这段神秘的程序  阅读全文
posted @ 2007-08-23 23:49 力为 阅读(1932) | 评论 (3)  编辑

     摘要: 小小技巧,有更好的不?  阅读全文
posted @ 2006-08-30 15:30 力为 阅读(1904) | 评论 (1)  编辑

     摘要: 问题:
有时候用ifstream或ofstream打开带有中文路径的文件会失败。  阅读全文
posted @ 2006-06-09 22:01 力为 阅读(13290) | 评论 (13)  编辑

     摘要: 取得std::ostringstream里的内容可以通过str()和str(string&)成员函数。由于str()返回的是临时对象,因而会有如下误用……  阅读全文
posted @ 2006-06-08 16:49 力为 阅读(6400) | 评论 (5)  编辑

     摘要: 最近遇到这样一种情况:使用getline处理有相同text内容的std::ifstream和std::istringstream时,得到的结果有差异。从std::istringstream中返回的一行会多出一个不可见的'\r'符号。  阅读全文
posted @ 2006-06-08 15:40 力为 阅读(2845) | 评论 (3)  编辑

     摘要: VC2005编译一个ATL工程的时候,出现这样一条错误:
midl : command line error MIDL1004 : cannot execute C preprocessor cl.exe

  阅读全文
posted @ 2006-05-23 17:46 力为 阅读(5240) | 评论 (7)  编辑

     摘要: 有些情况下,Debug版的程序运行的正常,可是用Release版就出问题了,网上有很多解决办法。最近,我不幸也遇到了这种情况,不过解决方法却很简单——更改编译选项。  阅读全文
posted @ 2005-12-28 11:08 力为 阅读(6019) | 评论 (9)  编辑

     摘要: 默认情况下,用科学计数法表示实数,输出的指数位数为3。如何控制使其只输出2位指数位?VC6下如何?VC2005又如何?  阅读全文
posted @ 2005-12-18 20:39 力为 阅读(5757) | 评论 (0)  编辑

posted @ 2005-11-03 10:14 力为 阅读(7597) | 评论 (14)  编辑

     摘要: 如何通过FILE*操作内存文件?----一个有难度的问题  阅读全文
posted @ 2005-10-14 17:30 力为 阅读(7556) | 评论 (11)  编辑