<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ti</title>
	<atom:link href="http://www.tiham.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.tiham.com</link>
	<description>耕耘内心  自求沉静</description>
	<lastBuildDate>Mon, 26 Dec 2011 03:46:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>《一江春水向东流》</title>
		<link>http://www.tiham.com/2011/12/huawei-2.html</link>
		<comments>http://www.tiham.com/2011/12/huawei-2.html#comments</comments>
		<pubDate>Mon, 26 Dec 2011 03:46:50 +0000</pubDate>
		<dc:creator>Ti</dc:creator>
				<category><![CDATA[江湖]]></category>
		<category><![CDATA[任正非]]></category>

		<guid isPermaLink="false">http://www.tiham.com/?p=1007</guid>
		<description><![CDATA[小时候，妈妈给我们讲希腊大力神的故事，我们崇拜得不得了。少年不知事的时期我们崇拜上李元霸、宇文成都这种盖世英雄，传播着张飞“杀”(争斗)岳飞的荒诞故事。在青春萌动的时期，突然敏感到李清照的千古情人是力拔山兮的项羽。至此“生当作人杰，死亦为鬼雄”又成了我们的人生警句。当然这种个人英雄主义，也不是没有意义，它迫使我们在学习上争斗，成就了较好的成绩。]]></description>
			<content:encoded><![CDATA[<blockquote><p>任正非在圣诞节发表<br />
全文如下：</p></blockquote>
<p><strong>一江春水向东流 任正非 2011年12月25日</strong></p>
<p>千古兴亡多少事，一江春水向东流。</p>
<p>小时候，妈妈给我们讲希腊大力神的故事，我们崇拜得不得了。少年不知事的时期我们崇拜上李元霸、宇文成都这种盖世英雄，传播着张飞“杀”(争斗)岳飞的荒诞故事。在青春萌动的时期，突然敏感到李清照的千古情人是力拔山兮的项羽。至此“生当作人杰，死亦为鬼雄”又成了我们的人生警句。当然这种个人英雄主义，也不是没有意义，它迫使我们在学习上争斗，成就了较好的成绩。</p>
<p>当我走向社会，多少年后才知道，我碰到头破血流的，就是这种不知事的人生哲学。我大学没入了团，当兵多年没入了党，处处都处在人生逆境，个人很孤立，当我明白团结就是力量这句话的政治内涵时，已过了不惑之年。想起蹉跎了的岁月，才觉得，怎么会这么幼稚可笑，一点都不明白开放、妥协、灰度呢？</p>
<p>我是在生活所迫，人生路窄的时候，创立华为的。那时我已领悟到个人才是历史长河中最渺小的，这个人生真谛。我看过云南的盘山道，那么艰险，一百多年前是怎么确定路线，怎么修筑的，为筑路人的智慧与辛苦佩服；我看过薄薄的丝绸衣服，以及为上面栩栩如生的花纹是怎么织出来的，而折服，织女们怎么这么巧夺天工？天啊！不仅万里长城、河边的纤夫、奔驰的高铁……我深刻地体会到，组织的力量、众人的力量，才是力大无穷的。人感知自己的渺小，行为才开始伟大。在创立华为时，我已过了不惑之年。不惑是什么意思，是几千年的封建社会，环境变动缓慢，等待人的心理成熟的一个尺度。而我进入不惑之年时，人类已进入电脑时代，世界开始疯起来了，等不得我的不惑了。</p>
<p>我突然发觉自己本来是优秀的中国青年，所谓的专家，竟然越来越无知。不是不惑，而是要重新起步新的学习，时代已经没时间与机会，让我不惑了，前程充满了不确定性。我刚来深圳还准备从事技术工作，或者搞点科研的，如果我选择这条路，早已被时代抛在垃圾堆里了。我后来明白，一个人不管如何努力，永远也赶不上时代的步伐，更何况知识爆炸的时代。只有组织起数十人、数百人、数千人一同奋斗，你站在这上面，才摸得到时代的脚。我转而去创建华为时，不再是自己去做专家，而是做组织者。在时代前面，我越来越不懂技术、越来越不懂财务、半懂不懂管理，如果不能民主的善待团体，充分发挥各路英雄的作用，我将一事无成。从事组织建设成了我后来的追求，如何组织起千军万马，这对我来说是天大的难题。我创建了华为公司，当时在中国叫个体户，这么一个弱小的个体户，想组织起千军万马，是有些狂妄，不合时宜，是有些想吃天鹅肉的梦幻。</p>
<p>我创建公司时设计了员工持股制度，通过利益分享，团结起员工，那时我还不懂期权制度，更不知道西方在这方面很发达，有多种形式的激励机制。仅凭自己过去的人生挫折，感悟到与员工分担责任，分享利益。创立之初我与我父亲相商过这种做法，结果得到他的大力支持，他在卅年代学过经济学。这种无意中插的花，竟然今天开放到如此鲜艳，成就华为的大事业。</p>
<p>在华为成立之初，我是听任各地“游击队长”们自由发挥的。其实，我也领导不了他们。前十年几乎没有开过办公会类似的会议，总是飞到各地去，听取他们的汇报，他们说怎么办就怎么办，理解他们，支持他们；听听研发人员的发散思维，乱成一团的所谓研发，当时简直不可能有清晰的方向，像玻璃窗上的苍蝇，乱碰乱撞，听客户一点点改进的要求，就奋力去找机会......。更谈不上如何去管财务的了，我根本就不懂财务，这与我后来没有处理好与财务的关系，他们被提拔少，责任在我。也许是我无能、傻、才如此放权，使各路诸侯的聪明才智大发挥，成就了华为。我那时被称作甩手掌柜，不是我甩手，而是我真不知道如何管。今天的接班人们，个个都是人中精英，他们还会不会像我那么愚钝，继续放权，发挥全体的积极性，继往开来，承前启后呢？他们担任的事业更大，责任更重，会不会被事务压昏了，没时间听下面唠叨了呢……。相信华为的惯性，相信接班人们的智慧。</p>
<p>到97年后，公司内部的思想混乱，主义林立，各路诸侯都显示出他们的实力，公司往何处去，不得要领。我请人民大学的教授们，一起讨论一个“基本法”，用于集合一下大家发散的思维，几上几下的讨论，不知不觉中“春秋战国”就无声无息了，人大的教授厉害，怎么就统一了大家的认识了呢？从此，开始形成了所谓的华为企业文化，说这个文化有多好，多厉害，不是我创造的，而是全体员工悟出来的。我那时最多是从一个甩手掌柜，变成了一个文化教员。业界老说我神秘、伟大，其实我知道自己，名实不符。我不是为了抬高自己，而隐起来，而是因害怕而低调的。真正聪明的是十三万员工，以及客户的宽容与牵引，我只不过用利益分享的方式，将他们的才智粘合起来。</p>
<p>公司在意志适当集中以后，就必须产生必要的制度来支撑这个文化，这时，我这个假掌柜就躲不了了，从上世纪末，到本世纪初，大约在2003年前的几年时间，我累坏了，身体就是那时累垮的。身体有多项疾病，动过两次癌症手术，但我乐观……。那时，要出来多少文件才能指导，约束公司的运行，那时公司已有几万员工，而且每天还在不断大量地涌入。你可以想象混乱到什么样子。我理解了，社会上那些承受不了的高管，为什么选择自杀。问题集中到你这一点，你不拿主意就无法运行，把你聚焦在太阳下烤，你才知道CEO不好当。每天十多个小时以上的工作，仍然是一头雾水，衣服皱巴巴的，内外矛盾交集。我人生中并没有合适的管理经历，从学校，到军队，都没有做过有行政权力的“官”，不可能有产生出有效文件的素质，左了改，右了又改过来，反复烙饼，把多少优秀人才烙糊了，烙跑了……。这段时间的摸着石头过河，险些被水淹死。</p>
<p>2002年，公司差点崩溃了。IT泡沫的破灭，公司内外矛盾的交集，我却无能为力控制这个公司，有半年时间都是噩梦，梦醒时常常哭。真的，不是公司的骨干们，在茫茫黑暗中，点燃自己的心，来照亮前进的路程，现在公司早已没有了。这段时间孙董事长团结员工，增强信心，功不可没。</p>
<p>大约2004年，美国顾问公司帮助我们设计公司组织结构时，认为我们还没有中枢机构，不可思议。而且高层只是空任命，也不运作，提出来要建立EMT(Executive Management Team)，我不愿做EMT的主席，就开始了轮值主席制度，由八位领导轮流执政，每人半年，经过两个循环，演变到今年的轮值CEO制度。也许是这种无意中的轮值制度，平衡了公司各方面的矛盾，使公司得以均衡成长。轮值的好处是，每个轮值者，在一段时间里，担负了公司COO的职责，不仅要处理日常事务，而且要为高层会议准备起草文件，大大地锻炼了他们。同时，他不得不削小他的屁股，否则就达不到别人对他决议的拥护。这样他就将他管辖的部门，带入了全局利益的平衡，公司的山头无意中在这几年削平了。</p>
<p>经历了八年轮值后，在新董事会选举中，他们多数被选上。我们又开始了在董事会领导下的轮值CEO制度，他们在轮值期间是公司的最高的行政首长。他们更多的是着眼公司的战略，着眼制度建设。将日常经营决策的权力进一步下放给各BG、区域，以推动扩张的合理进行。这比将公司的成功系于一人，败也是这一人的制度要好。每个轮值CEO在轮值期间奋力地拉车，牵引公司前进。他走偏了，下一轮的轮值CEO会及时去纠正航向，使大船能早一些拨正船头。避免问题累积过重不得解决。</p>
<p>我不知道我们的路能走多好，这需要全体员工的拥护，以及客户和合作伙伴的理解与支持。我相信由于我的不聪明，引出来的集体奋斗与集体智慧，若能为公司的强大、为祖国、为世界作出一点贡献，廿多年的辛苦就值得了。我知识的底蕴不够，也并不够聪明，但我容得了优秀的员工与我一起工作，与他们在一起，我也被熏陶得优秀了。他们出类拔萃，夹着我前进，我又没有什么退路，不得不被“绑”着，“架”着往前走，不小心就让他们抬到了峨眉山顶。我也体会到团结合作的力量。这些年来进步最大的是我，从一个“土民”，被精英们抬成了一个体面的小老头。因为我的性格像海绵一样，善于吸取他们的营养，总结他们的精华，而且大胆地开放输出。那些人中精英，在时代的大潮中，更会被众人团结合作抬到喜马拉雅山顶。希腊大力神的母亲是大地，他只要一靠在大地上就力大无穷。我们的大地就是众人和制度，相信制度的力量，会使他们团结合作把公司抬到金顶的。</p>
<p>作为轮值CEO，他们不再是只关注内部的建设与运作，同时，也要放眼外部，放眼世界，要自己适应外部环境的运作，趋利避害。我们伸出头去，看见我们现在是处在一个多变的世界，风暴与骄阳，和煦的春光与万丈深渊……并存着。我们无法准确预测未来，仍要大胆拥抱未来。面对潮起潮落，即使公司大幅度萎缩，我们不仅要淡定，也要矢志不移地继续推动组织朝向长期价值贡献的方向去改革。要改革，更要开放。要去除成功的惰性与思维的惯性对队伍的影响，也不能躺在过去荣耀的延长线上，只要我们能不断地激活队伍，我们就有希望。历史的灾难经常是周而复始的，人们的贪婪，从未因灾难改进过，过高的杠杆比，推动经济的泡沫化，总会破灭。</p>
<p>我们唯有把握更清晰的方向，更努力地工作，任何投机总会要还账的。经济越来越不可控，如果金融危机的进一步延伸爆炸，货币急剧贬值，外部社会动荡，我们会独善其身吗？我们有能力挽救自己吗？我们行驶的航船，员工会像韩国人卖掉金首饰救国家一样，给我们集资买油吗？历史没有终结，繁荣会永恒吗？我们既要有信心，也不要盲目相信未来，历史的灾难，都是我们的前车之鉴。我们对未来的无知是无法解决的问题，但我们可以通过归纳找到方向，并使自己处在合理组织结构及优良的进取状态，以此来预防未来。死亡是会到来的，这是历史规律，我们的责任是应不断延长我们的生命。</p>
<p>千古兴亡多少事，一江春水向东流，流过太平洋，流过印度洋，……不回头。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tiham.com/2011/12/huawei-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>各家SVM工具 无排名</title>
		<link>http://www.tiham.com/2011/12/svm-tools.html</link>
		<comments>http://www.tiham.com/2011/12/svm-tools.html#comments</comments>
		<pubDate>Wed, 14 Dec 2011 12:35:13 +0000</pubDate>
		<dc:creator>Ti</dc:creator>
				<category><![CDATA[算法]]></category>
		<category><![CDATA[libsvm]]></category>
		<category><![CDATA[svm]]></category>
		<category><![CDATA[SvmLight]]></category>

		<guid isPermaLink="false">http://www.tiham.com/?p=1003</guid>
		<description><![CDATA[只试过SvmLight 与 LibSvm，好像也是主流，其它性能不知如何。]]></description>
			<content:encoded><![CDATA[<p>只试过SvmLight 与 LibSvm，好像也是主流，其它性能不知如何。</p>
<table width="406" border="1" cellspacing="1" cellpadding="1">
<tbody>
<tr>
<td style="width: 50px;"><strong>史称</strong></td>
<td style="width: 50px;"><strong>作者</strong></td>
<td style="width: 50px;"><strong>机构</strong></td>
<td style="width: 50px;"><strong>语言</strong></td>
<td style="width: 50px;"><strong>环境</strong></td>
<td style="width: 50px;"><strong>多类</strong></td>
<td style="width: 50px;"><strong>回归</strong></td>
<td style="width: 50px;"><strong>说明</strong></td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.csie.ntu.edu.tw/%7Ecjlin/bsvm/">BSVM</a></td>
<td>Chih-Wei Hsu and Chih-Jen Lin</td>
<td>National Taiwan University</td>
<td>C++</td>
<td>Win</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.equbits.com/">Equbits Foresight</a></td>
<td>Equbits LLC</td>
<td>Equbits LLC</td>
<td>SDK</td>
<td>Win</td>
<td>???</td>
<td>Yes</td>
<td>Commercial. Contact Equibits LLC for details</td>
</tr>
<tr>
<td><a rel="nofollow" href="http://bach.ece.jhu.edu/svm/ginisvm/">Gini-SVM</a></td>
<td>Shantanu Chakrabartty</td>
<td>Johns Hopkins University</td>
<td>C++</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
<td>Handles non positive definite kernels</td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.cenparmi.concordia.ca/%7Epeople/jdong/HeroSvm.html">HeroSvm</a></td>
<td>Jianxiong Dong</td>
<td>Concordia University</td>
<td>C++</td>
<td>Win</td>
<td>Yes</td>
<td>No</td>
<td>Optimized for Pentium 4</td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.support-vector.ws/html/downloads.html">LEARNSC</a></td>
<td>Vojislav Kecman</td>
<td></td>
<td>Matlab p-files</td>
<td>N/A</td>
<td>Yes</td>
<td>Yes</td>
<td>Must pay for source!</td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.csie.ntu.edu.tw/%7Ecjlin/libsvm/">LIBSVM</a></td>
<td>Chih-Chung Chang, Chih-Jen Lin</td>
<td>National Taiwan University</td>
<td>C++, Java, Python, R, MATLAB, Perl, Ruby</td>
<td>Win/*nix</td>
<td>Yes</td>
<td>Yes</td>
<td>Graphic interface available</td>
</tr>
<tr>
<td>LS-SVMlab</td>
<td>Kristiaan Pelckmans, Johan Suykens</td>
<td>Katholieke Universiteit Leuven</td>
<td>Matlab</td>
<td>Win/*nix</td>
<td>Yes</td>
<td>Yes</td>
<td>Comes with platform-specific MEX files</td>
</tr>
<tr>
<td>Matlab SVM Toolbox</td>
<td>S. R. Gunn</td>
<td>University of Southampton</td>
<td>Matlab</td>
<td>N/A</td>
<td>No</td>
<td>Yes</td>
<td>Includes a simple GUI</td>
</tr>
<tr>
<td>mySVM</td>
<td>Stefan Ruping</td>
<td>Universitat Dortmund</td>
<td>C++</td>
<td>Win/*nix</td>
<td>No</td>
<td>Yes</td>
<td></td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.ece.osu.edu/%7Emaj/osu_svm/">OSU</a></td>
<td>Junshui Ma, Yi Zhao, and Stanley Ahalt</td>
<td>Ohio State University</td>
<td>Matlab</td>
<td>N/A</td>
<td>Yes</td>
<td>Yes</td>
<td>Matlab interface to LIBSVM</td>
</tr>
<tr>
<td><a rel="nofollow" href="http://dm.unife.it/gpdt/">Parallel GPDT</a></td>
<td>T. Serafini, G. Zanghirati, L. Zanni</td>
<td>Universita di Ferrara</td>
<td>C++</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>Designed for parallel systems</td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.procoders.net/en/Procoders/open_source/pcSVM">pcSVM</a></td>
<td></td>
<td>Procoders.net</td>
<td>C</td>
<td>-</td>
<td>No</td>
<td>No</td>
<td></td>
</tr>
<tr>
<td><a rel="nofollow" href="http://research.microsoft.com/MLP/RVM/">RVMs</a></td>
<td>Mike Tipping</td>
<td>MSR Cambridge</td>
<td>Matlab</td>
<td>-</td>
<td>Yes</td>
<td>Yes</td>
<td></td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.kyb.tuebingen.mpg.de/bs/people/spider/">SpiderSVM</a></td>
<td>Jason Weston, Andre Elisseeff , Gokhan BakIr , Fabian Sinz</td>
<td>Max Planck Institute for Biological Cybernetics</td>
<td>Matlab</td>
<td>N/A</td>
<td>Yes</td>
<td>Yes</td>
<td>Part of the Spider machine learning library</td>
</tr>
<tr>
<td><a rel="nofollow" href="http://cmp.felk.cvut.cz/%7Exfrancv/stprtool/">Statistical Pattern Recognition Toolbox for MATLAB </a></td>
<td>Vojtech Franc and Vaclav Hlavac</td>
<td>Czech Technical University Prague</td>
<td>Matlab/C</td>
<td>No</td>
<td>Yes</td>
<td>No</td>
<td>Good online documentation. Everything I′ve tried has worked <span style="color: #ffffff;">字串9</span>well. Lots of stuff besides SVMs.</td>
</tr>
<tr>
<td>SVMdark</td>
<td>Martin Sewell</td>
<td>University College London</td>
<td>C</td>
<td>Win</td>
<td>No</td>
<td>Yes</td>
<td></td>
</tr>
<tr>
<td><a rel="nofollow" href="http://fpn.mit.edu/SvmFu">SvmFu</a></td>
<td>Ryan Rifkin</td>
<td>MIT</td>
<td>C++</td>
<td>No</td>
<td></td>
<td>No</td>
<td>Must be compiled with g++</td>
</tr>
<tr>
<td>SVMLight</td>
<td>Thorsten Joachims</td>
<td>Cornell University</td>
<td>C</td>
<td>Win/*nix</td>
<td>No</td>
<td>Yes</td>
<td></td>
</tr>
<tr>
<td><a rel="nofollow" href="http://cmp.felk.cvut.cz/%7Exfrancv/stprtool/">SVMsequel</a></td>
<td>Hal Daume III</td>
<td>University of Southern California</td>
<td>OCaml</td>
<td>No</td>
<td>Yes</td>
<td>No</td>
<td>"Very fast and handles enormous datasets nicely"</td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.idiap.ch/machine_learning.php?content=Torch/en_SVMTorch.txt">SVMtorch</a></td>
<td>Ronan Collobert and Samy Bengio</td>
<td>IDIAP</td>
<td>C++</td>
<td>No</td>
<td>?</td>
<td>Yes</td>
<td></td>
</tr>
<tr>
<td>SVM Toolbox</td>
<td>Gavin Cawley</td>
<td>University of East Anglia Norwich</td>
<td>Matlab/C++</td>
<td>No</td>
<td>Yes</td>
<td>No</td>
<td>Beta version</td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.cs.ucl.ac.uk/staff/M.Sewell/winsvm/">WinSVM</a></td>
<td>Martin Sewell</td>
<td>University College London</td>
<td>C++</td>
<td>Win</td>
<td>No</td>
<td>Yes</td>
<td></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.tiham.com/2011/12/svm-tools.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>具体化SerializeElements</title>
		<link>http://www.tiham.com/2011/12/explicit-serializeelements.html</link>
		<comments>http://www.tiham.com/2011/12/explicit-serializeelements.html#comments</comments>
		<pubDate>Tue, 13 Dec 2011 18:45:47 +0000</pubDate>
		<dc:creator>Ti</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[vs2011]]></category>

		<guid isPermaLink="false">http://www.tiham.com/?p=1001</guid>
		<description><![CDATA[一程序从vc6.0上移植到vs2011，其中需要串行化CList，由于CList参数是个类，要重写SerializeElements方法。原来代码SerializeElements是用非模板函数重写，发现总是断点不到。我们知道现在第三代具体化(ISO/ANSI C++标准)中非模板函数算最大，它将覆盖具体化和常规模板，难道vs2001是非官方草案版模板的编译器？？ 只能暂时改成具体化实现，它将覆盖MFC常规模板。]]></description>
			<content:encoded><![CDATA[<p>一程序从vc6.0上移植到vs2011，其中需要串行化CList，由于CList参数是个类，要重写SerializeElements方法。原来代码SerializeElements是用非模板函数重写，发现总是断点不到。我们知道现在第三代具体化(ISO/ANSI C++标准)中非模板函数算最大，它将覆盖具体化和常规模板，难道vs2001是非官方草案版模板的编译器？？ 只能暂时改成具体化实现，它将覆盖MFC常规模板。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">template <span style="color: #339933;">&lt;&gt;</span> <span style="color: #993333;">void</span> AFXAPI SerializeElements <span style="color: #339933;">&lt;</span>CCatalogNode<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#40;</span>CArchive<span style="color: #339933;">&amp;</span> ar<span style="color: #339933;">,</span> CCatalogNode<span style="color: #339933;">*</span> pElements<span style="color: #339933;">,</span> INT_PTR nCount<span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p><span id="more-1001"></span><br />
CATALOGLIST.H</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">class CCatalogNode
<span style="color: #009900;">&#123;</span>
public<span style="color: #339933;">:</span>
	CCatalogNode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	~CCatalogNode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	CCatalogNode<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> CCatalogNode<span style="color: #339933;">&amp;</span> x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">const</span> CCatalogNode<span style="color: #339933;">&amp;</span> operator <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> CCatalogNode<span style="color: #339933;">&amp;</span> x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">const</span> CCatalogNode<span style="color: #339933;">&amp;</span> operator <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> CCatalogNode<span style="color: #339933;">&amp;</span> x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
public<span style="color: #339933;">:</span>
	<span style="color: #993333;">void</span> Serialize<span style="color: #009900;">&#40;</span>CArchive<span style="color: #339933;">&amp;</span> ar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
public<span style="color: #339933;">:</span>
	<span style="color: #993333;">short</span> m_idxCata<span style="color: #339933;">;</span>
	CString	m_strCatalogName<span style="color: #339933;">;</span>
	CString m_strDirName<span style="color: #339933;">;</span>
	<span style="color: #993333;">long</span>	m_lTotalWordNum<span style="color: #339933;">;</span>
private<span style="color: #339933;">:</span>
	<span style="color: #666666; font-style: italic;">//CList&lt;CString,CString&amp;&gt;			m_lstDocList;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//void AFXAPI SerializeElements(CArchive&amp; ar,CCatalogNode* pElements,int nCount);</span>
&nbsp;
&nbsp;
class CCatalogList  
<span style="color: #009900;">&#123;</span>
public<span style="color: #339933;">:</span>
	CCatalogList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	virtual ~CCatalogList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">const</span> CCatalogList<span style="color: #339933;">&amp;</span> operator <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> CCatalogList<span style="color: #339933;">&amp;</span> x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">const</span> CCatalogList<span style="color: #339933;">&amp;</span> operator <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> CCatalogList<span style="color: #339933;">&amp;</span> x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">void</span> InitCatalogList<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> nMode<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">void</span> DumpToFile <span style="color: #009900;">&#40;</span>CString strFileName<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> nSaveMode<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	BOOL GetFromFile<span style="color: #009900;">&#40;</span>CString strFileName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
public<span style="color: #339933;">:</span>
	CCatalogNode GetAt<span style="color: #009900;">&#40;</span>POSITION pos<span style="color: #009900;">&#41;</span> <span style="color: #993333;">const</span><span style="color: #339933;">;</span>
	CCatalogNode<span style="color: #339933;">&amp;</span> GetAt<span style="color: #009900;">&#40;</span>POSITION pos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	CCatalogNode<span style="color: #339933;">&amp;</span> GetNext<span style="color: #009900;">&#40;</span>POSITION<span style="color: #339933;">&amp;</span> rPos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	POSITION AddCata<span style="color: #009900;">&#40;</span>CCatalogNode<span style="color: #339933;">&amp;</span> catanode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">void</span> Serialize<span style="color: #009900;">&#40;</span>CArchive<span style="color: #339933;">&amp;</span> ar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
private<span style="color: #339933;">:</span>
	CList<span style="color: #339933;">&lt;</span>CCatalogNode<span style="color: #339933;">,</span>CCatalogNode<span style="color: #339933;">&amp;&gt;</span>	m_lstCatalogList<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//void AFXAPI SerializeElements(CArchive&amp; ar,CCatalogList* pElements,int nCount);</span></pre></td></tr></table></div>

<p>CATALOGLIST.CPP</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">CCatalogNode<span style="color: #339933;">::</span><span style="color: #202020;">CCatalogNode</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> CCatalogNode<span style="color: #339933;">&amp;</span> x<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #339933;">*</span>this<span style="color: #339933;">=</span>x<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//类节点构造</span>
<span style="color: #993333;">const</span> CCatalogNode<span style="color: #339933;">&amp;</span> CCatalogNode<span style="color: #339933;">::</span><span style="color: #202020;">operator</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> CCatalogNode<span style="color: #339933;">&amp;</span> x<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>this<span style="color: #339933;">==&amp;</span>x<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #339933;">*</span>this<span style="color: #339933;">;</span>
	m_lTotalWordNum <span style="color: #339933;">=</span> x.<span style="color: #202020;">m_lTotalWordNum</span> <span style="color: #339933;">;</span>
	m_strCatalogName<span style="color: #339933;">=</span>x.<span style="color: #202020;">m_strCatalogName</span><span style="color: #339933;">;</span>
	m_strDirName<span style="color: #339933;">=</span>x.<span style="color: #202020;">m_strDirName</span><span style="color: #339933;">;</span>
	m_idxCata<span style="color: #339933;">=</span>x.<span style="color: #202020;">m_idxCata</span><span style="color: #339933;">;</span>
	<span style="color: #808080; font-style: italic;">/*
	m_lstDocList.RemoveAll();
	POSITION pos = x.m_lstDocList.GetHeadPosition();
	while(pos!=NULL)
	{
		CString docnode=x.m_lstDocList.GetNext(pos);
		m_lstDocList.AddTail(docnode);
	}
	*/</span>
	<span style="color: #b1b100;">return</span> <span style="color: #339933;">*</span>this<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">const</span> CCatalogNode<span style="color: #339933;">&amp;</span> CCatalogNode<span style="color: #339933;">::</span><span style="color: #202020;">operator</span> <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> CCatalogNode<span style="color: #339933;">&amp;</span> x<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>this<span style="color: #339933;">==&amp;</span>x<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #339933;">*</span>this<span style="color: #339933;">;</span>
	m_lTotalWordNum <span style="color: #339933;">+=</span> x.<span style="color: #202020;">m_lTotalWordNum</span> <span style="color: #339933;">;</span>
	m_strCatalogName<span style="color: #339933;">=</span>x.<span style="color: #202020;">m_strCatalogName</span><span style="color: #339933;">;</span>
	m_strDirName<span style="color: #339933;">=</span>x.<span style="color: #202020;">m_strDirName</span><span style="color: #339933;">;</span>
	m_idxCata<span style="color: #339933;">=</span>x.<span style="color: #202020;">m_idxCata</span><span style="color: #339933;">;</span>
	<span style="color: #808080; font-style: italic;">/*
	POSITION pos = x.m_lstDocList.GetHeadPosition();
	while(pos!=NULL)
	{
		CString docnode=x.m_lstDocList.GetNext(pos);
		m_lstDocList.AddTail(docnode);
	}
	*/</span>
	<span style="color: #b1b100;">return</span> <span style="color: #339933;">*</span>this<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
CCatalogNode<span style="color: #339933;">::</span><span style="color: #202020;">CCatalogNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	m_idxCata<span style="color: #339933;">=-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
&nbsp;
	m_lTotalWordNum<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
CCatalogNode<span style="color: #339933;">::</span>~CCatalogNode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
CCatalogList<span style="color: #339933;">::</span><span style="color: #202020;">CCatalogList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
CCatalogList<span style="color: #339933;">::</span>~CCatalogList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//nSaveMode&lt;=0 保存文档的向量</span>
<span style="color: #666666; font-style: italic;">//nSaveMode&gt;0  不保存文档的向量</span>
<span style="color: #993333;">void</span> CCatalogList<span style="color: #339933;">::</span><span style="color: #202020;">DumpToFile</span><span style="color: #009900;">&#40;</span>CString strFileName<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> nSaveMode<span style="color: #009900;">&#41;</span>  <span style="color: #666666; font-style: italic;">// view the word list content</span>
<span style="color: #009900;">&#123;</span>
	CFile		fBinOut<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>fBinOut.<span style="color: #202020;">Open</span><span style="color: #009900;">&#40;</span>strFileName<span style="color: #339933;">,</span>CFile<span style="color: #339933;">::</span><span style="color: #202020;">modeWrite</span> <span style="color: #339933;">|</span> CFile<span style="color: #339933;">::</span><span style="color: #202020;">modeCreate</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		AfxMessageBox<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;无法创建文件&quot;</span><span style="color: #339933;">+</span>strFileName<span style="color: #339933;">+</span><span style="color: #ff0000;">&quot;!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	CArchive ar<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>fBinOut<span style="color: #339933;">,</span>CArchive<span style="color: #339933;">::</span><span style="color: #202020;">store</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	Serialize<span style="color: #009900;">&#40;</span>ar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	ar.<span style="color: #202020;">Close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	fBinOut.<span style="color: #202020;">Close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
BOOL CCatalogList<span style="color: #339933;">::</span><span style="color: #202020;">GetFromFile</span><span style="color: #009900;">&#40;</span>CString strFileName<span style="color: #009900;">&#41;</span>  <span style="color: #666666; font-style: italic;">// view the word list content</span>
<span style="color: #009900;">&#123;</span>
	CFile	nfBinOut<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>nfBinOut.<span style="color: #202020;">Open</span><span style="color: #009900;">&#40;</span>strFileName<span style="color: #339933;">,</span>CFile<span style="color: #339933;">::</span><span style="color: #202020;">typeBinary</span><span style="color: #339933;">|</span>CFile<span style="color: #339933;">::</span><span style="color: #202020;">modeRead</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		AfxMessageBox<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;无法打开文件&quot;</span><span style="color: #339933;">+</span>strFileName<span style="color: #339933;">+</span><span style="color: #ff0000;">&quot;!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> FALSE<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #808080; font-style: italic;">/*
	char sRead[100]; 
	nfBinOut.Read(sRead,100);
	int i=0;
	while(i&lt;100)
	{
		std::cout&lt;&lt;sRead[i];
		i++;
	}
	*/</span>
&nbsp;
	CArchive ar<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>nfBinOut<span style="color: #339933;">,</span>CArchive<span style="color: #339933;">::</span><span style="color: #202020;">load</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	Serialize<span style="color: #009900;">&#40;</span>ar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	ar.<span style="color: #202020;">Close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	nfBinOut.<span style="color: #202020;">Close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> TRUE<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> CCatalogList<span style="color: #339933;">::</span><span style="color: #202020;">Serialize</span><span style="color: #009900;">&#40;</span>CArchive <span style="color: #339933;">&amp;</span>ar<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	m_lstCatalogList.<span style="color: #202020;">Serialize</span><span style="color: #009900;">&#40;</span>ar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//void AFXAPI SerializeElements(CArchive&amp; ar,CCatalogNode* pElements,int nCount)</span>
template <span style="color: #339933;">&lt;&gt;</span> <span style="color: #993333;">void</span> AFXAPI SerializeElements <span style="color: #339933;">&lt;</span>CCatalogNode<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#40;</span>CArchive<span style="color: #339933;">&amp;</span> ar<span style="color: #339933;">,</span> CCatalogNode<span style="color: #339933;">*</span> pElements<span style="color: #339933;">,</span> INT_PTR nCount<span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
	ASSERT<span style="color: #009900;">&#40;</span>nCount<span style="color: #339933;">==</span><span style="color: #0000dd;">0</span><span style="color: #339933;">||</span>
		AfxIsValidAddress<span style="color: #009900;">&#40;</span>pElements<span style="color: #339933;">,</span>nCount<span style="color: #339933;">*</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>CCatalogNode<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	pElements<span style="color: #339933;">-&gt;</span>Serialize<span style="color: #009900;">&#40;</span>ar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #993333;">void</span> AFXAPI SerializeElements<span style="color: #009900;">&#40;</span>CArchive<span style="color: #339933;">&amp;</span> ar<span style="color: #339933;">,</span>CCatalogList<span style="color: #339933;">*</span> pElements<span style="color: #339933;">,</span><span style="color: #993333;">int</span> nCount<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	ASSERT<span style="color: #009900;">&#40;</span>nCount<span style="color: #339933;">==</span><span style="color: #0000dd;">0</span><span style="color: #339933;">||</span>
		AfxIsValidAddress<span style="color: #009900;">&#40;</span>pElements<span style="color: #339933;">,</span>nCount<span style="color: #339933;">*</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>CCatalogList<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	pElements<span style="color: #339933;">-&gt;</span>Serialize<span style="color: #009900;">&#40;</span>ar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> CCatalogNode<span style="color: #339933;">::</span><span style="color: #202020;">Serialize</span><span style="color: #009900;">&#40;</span>CArchive <span style="color: #339933;">&amp;</span>ar<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>ar.<span style="color: #202020;">IsStoring</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		ar<span style="color: #339933;">&lt;&lt;</span>m_idxCata<span style="color: #339933;">;</span>
		ar<span style="color: #339933;">&lt;&lt;</span>m_strDirName<span style="color: #339933;">;</span>
		ar<span style="color: #339933;">&lt;&lt;</span>m_lTotalWordNum<span style="color: #339933;">;</span>
		ar<span style="color: #339933;">&lt;&lt;</span>m_strCatalogName<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #009900;">&#123;</span>
		ar<span style="color: #339933;">&gt;&gt;</span>m_idxCata<span style="color: #339933;">;</span>
		ar<span style="color: #339933;">&gt;&gt;</span>m_strDirName<span style="color: #339933;">;</span>
		ar<span style="color: #339933;">&gt;&gt;</span>m_lTotalWordNum<span style="color: #339933;">;</span>
		ar<span style="color: #339933;">&gt;&gt;</span>m_strCatalogName<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">//m_lstDocList.Serialize(ar);</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">const</span> CCatalogList<span style="color: #339933;">&amp;</span> CCatalogList<span style="color: #339933;">::</span><span style="color: #202020;">operator</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> CCatalogList<span style="color: #339933;">&amp;</span> x<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>this<span style="color: #339933;">==&amp;</span>x<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #339933;">*</span>this<span style="color: #339933;">;</span>
	m_lstCatalogList.<span style="color: #202020;">RemoveAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	POSITION pos <span style="color: #339933;">=</span> x.<span style="color: #202020;">m_lstCatalogList</span>.<span style="color: #202020;">GetHeadPosition</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>pos<span style="color: #339933;">!=</span>NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		CCatalogNode catanode<span style="color: #339933;">=</span>x.<span style="color: #202020;">m_lstCatalogList</span>.<span style="color: #202020;">GetNext</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		m_lstCatalogList.<span style="color: #202020;">AddTail</span><span style="color: #009900;">&#40;</span>catanode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #339933;">*</span>this<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">const</span> CCatalogList<span style="color: #339933;">&amp;</span> CCatalogList<span style="color: #339933;">::</span><span style="color: #202020;">operator</span> <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> CCatalogList<span style="color: #339933;">&amp;</span> x<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>this<span style="color: #339933;">==&amp;</span>x<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #339933;">*</span>this<span style="color: #339933;">;</span>
	POSITION pos <span style="color: #339933;">=</span> x.<span style="color: #202020;">m_lstCatalogList</span>.<span style="color: #202020;">GetHeadPosition</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>pos<span style="color: #339933;">!=</span>NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		CCatalogNode catanode<span style="color: #339933;">=</span>x.<span style="color: #202020;">m_lstCatalogList</span>.<span style="color: #202020;">GetNext</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		m_lstCatalogList.<span style="color: #202020;">AddTail</span><span style="color: #009900;">&#40;</span>catanode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #339933;">*</span>this<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//nMode&lt;=0 删除所有信息</span>
<span style="color: #666666; font-style: italic;">//nMode=1  删除所有文档,但保留类别(节点)</span>
<span style="color: #666666; font-style: italic;">//nMode=2  只删除文档向量所占用的内存</span>
<span style="color: #993333;">void</span> CCatalogList<span style="color: #339933;">::</span><span style="color: #202020;">InitCatalogList</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> nMode<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
POSITION CCatalogList<span style="color: #339933;">::</span><span style="color: #202020;">AddCata</span><span style="color: #009900;">&#40;</span>CCatalogNode <span style="color: #339933;">&amp;</span>catanode<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> m_lstCatalogList.<span style="color: #202020;">AddTail</span><span style="color: #009900;">&#40;</span>catanode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
CCatalogNode<span style="color: #339933;">&amp;</span> CCatalogList<span style="color: #339933;">::</span><span style="color: #202020;">GetNext</span><span style="color: #009900;">&#40;</span>POSITION <span style="color: #339933;">&amp;</span>rPos<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> m_lstCatalogList.<span style="color: #202020;">GetNext</span><span style="color: #009900;">&#40;</span>rPos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
CCatalogNode<span style="color: #339933;">&amp;</span> CCatalogList<span style="color: #339933;">::</span><span style="color: #202020;">GetAt</span><span style="color: #009900;">&#40;</span>POSITION pos<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> m_lstCatalogList.<span style="color: #202020;">GetAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tiham.com/2011/12/explicit-serializeelements.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>string、wstring、cstring、 char、 tchar、int、dword互转</title>
		<link>http://www.tiham.com/2011/12/string-wstring-cstring-char-tchar-int-dword.html</link>
		<comments>http://www.tiham.com/2011/12/string-wstring-cstring-char-tchar-int-dword.html#comments</comments>
		<pubDate>Mon, 05 Dec 2011 07:11:57 +0000</pubDate>
		<dc:creator>Ti</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://www.tiham.com/?p=1000</guid>
		<description><![CDATA[最近编程一直头痛字集中类型的转化，明知都可以转却总是记不住，不断的上网查来查去，在这里小结一下。以备以后方便使用，当然有些方法可能不是最新的，或者最简单的，但是对于自己已经了解的使用起来应该方便的多]]></description>
			<content:encoded><![CDATA[<p>最近编程一直头痛字集中类型的转化，明知都可以转却总是记不住，不断的上网查来查去，在这里小结一下。以备以后方便使用，当然有些方法可能不是最新的，或者最简单的，但是对于自己已经了解的使用起来应该方便的多：</p>
<h4>1》string 转 wstring</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">wstring s2ws<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> string<span style="color: #339933;">&amp;</span> s<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   _bstr_t t <span style="color: #339933;">=</span> s.<span style="color: #202020;">c_str</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #993333;">wchar_t</span><span style="color: #339933;">*</span> pwchar <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">wchar_t</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>t<span style="color: #339933;">;</span>
   wstring result <span style="color: #339933;">=</span> pwchar<span style="color: #339933;">;</span>
   <span style="color: #b1b100;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><span id="more-1000"></span></p>
<h4>2》wstring 转 string</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">string ws2s<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> wstring<span style="color: #339933;">&amp;</span> ws<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   _bstr_t t <span style="color: #339933;">=</span> ws.<span style="color: #202020;">c_str</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #993333;">char</span><span style="color: #339933;">*</span> pchar <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>t<span style="color: #339933;">;</span>
   string result <span style="color: #339933;">=</span> pchar<span style="color: #339933;">;</span>
   <span style="color: #b1b100;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>3》string 转 cstring</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">CString.<span style="color: #202020;">format</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%s&quot;</span><span style="color: #339933;">,</span> string.<span style="color: #202020;">c_str</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
<span style="color: #666666; font-style: italic;">//用c_str()确实比data()要好.</span></pre></td></tr></table></div>

<p>或：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">CString StringToCString<span style="color: #009900;">&#40;</span>string str<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   CString result<span style="color: #339933;">;</span>
   <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>str.<span style="color: #202020;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      result<span style="color: #339933;">+=</span>str<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #b1b100;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>4》cstring 转 string</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> ConvertCString2string<span style="color: #009900;">&#40;</span>CString<span style="color: #339933;">&amp;</span> strSrc<span style="color: #339933;">,</span>std<span style="color: #339933;">::</span><span style="color: #202020;">string</span><span style="color: #339933;">&amp;</span> strDes<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #339933;">#ifndef UNICODE</span>
   strDes <span style="color: #339933;">=</span> strSrc<span style="color: #339933;">;</span>
   <span style="color: #339933;">#else USES_CONVERSION;</span>
   strDes <span style="color: #339933;">=</span> W2A<span style="color: #009900;">&#40;</span>strSrc.<span style="color: #202020;">LockBuffer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   strSrc.<span style="color: #202020;">UnlockBuffer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #339933;">#endif</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>或：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">string s<span style="color: #009900;">&#40;</span>CString.<span style="color: #202020;">GetBuffer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
ReleaseBuffer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>；
GetBuffer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>后一定要ReleaseBuffer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>否则就没有释放缓冲区所占的空间.</pre></td></tr></table></div>

<p>或：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">string CStringToString<span style="color: #009900;">&#40;</span>CString cstr<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   string result<span style="color: #009900;">&#40;</span>cstr.<span style="color: #202020;">GetLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'e'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>cstr.<span style="color: #202020;">GetLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
       result<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span>cstr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #b1b100;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>5》string 转 char *</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>p <span style="color: #339933;">=</span> string.<span style="color: #202020;">c_str</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//举例： </span>
string aa<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;aaa&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>c<span style="color: #339933;">=</span>aa.<span style="color: #202020;">c_str</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
string mngName； 
<span style="color: #993333;">char</span> t<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">200</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
memset<span style="color: #009900;">&#40;</span>t<span style="color: #339933;">,</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span><span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
strcpy<span style="color: #009900;">&#40;</span>t<span style="color: #339933;">,</span>mngName.<span style="color: #202020;">c_str</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>或：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>p <span style="color: #339933;">=</span> new <span style="color: #993333;">char</span><span style="color: #009900;">&#91;</span>sring的长度<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
p<span style="color: #009900;">&#91;</span>string的长度<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #ff0000;">'/0'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//但是要注意最后赋值'/0'!!!</span>
&nbsp;
<span style="color: #993333;">char</span> <span style="color: #339933;">*</span> StringToChar<span style="color: #009900;">&#40;</span>string <span style="color: #339933;">&amp;</span>str<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #993333;">int</span> len<span style="color: #339933;">=</span>str.<span style="color: #202020;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> p<span style="color: #339933;">=</span> new <span style="color: #993333;">char</span><span style="color: #009900;">&#91;</span>len<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>len<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      p<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>str<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
   p<span style="color: #009900;">&#91;</span>len<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #ff0000;">'/0'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>6》char* 转 string</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">string s<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//你的只能初始化，在不是初始化的地方最好还是用assign()；</span>
string CharToString<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #339933;">*</span>arr<span style="color: #339933;">,</span><span style="color: #993333;">int</span> count<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   string result<span style="color: #009900;">&#40;</span>arr<span style="color: #339933;">,</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">//string是ansi编码字符char</span>
<span style="color: #666666; font-style: italic;">//TCHAR是unicode编码字符wchar_t</span></pre></td></tr></table></div>

<h4>7》string 转 TCHAR *</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
  wBuf 申明为指针即可。
*/</span>
<span style="color: #993333;">wchar_t</span> <span style="color: #339933;">*</span>chr2wch<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buffer<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        size_t len <span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        size_t wlen <span style="color: #339933;">=</span> MultiByteToWideChar<span style="color: #009900;">&#40;</span>CP_ACP<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>buffer<span style="color: #339933;">,</span> <span style="color: #993333;">int</span><span style="color: #009900;">&#40;</span>len<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">wchar_t</span> <span style="color: #339933;">*</span>wBuf <span style="color: #339933;">=</span> new <span style="color: #993333;">wchar_t</span><span style="color: #009900;">&#91;</span>wlen <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        MultiByteToWideChar<span style="color: #009900;">&#40;</span>CP_ACP<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>buffer<span style="color: #339933;">,</span> <span style="color: #993333;">int</span><span style="color: #009900;">&#40;</span>len<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> wBuf<span style="color: #339933;">,</span> <span style="color: #993333;">int</span><span style="color: #009900;">&#40;</span>wlen<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> wBuf<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>8》TCHAR * 转 string</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">char</span> <span style="color: #339933;">*</span> wch2chr<span style="color: #009900;">&#40;</span>LPCTSTR lpString<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;">// Calculate unicode string length.</span>
   UINT len <span style="color: #339933;">=</span> wcslen<span style="color: #009900;">&#40;</span>lpString<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
   <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buf <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span>len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   UINT i <span style="color: #339933;">=</span> wcstombs<span style="color: #009900;">&#40;</span>buf<span style="color: #339933;">,</span>lpString<span style="color: #339933;">,</span>len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">return</span> buf<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>9》char * 转 int</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
string 转 int
..............................
char* 转 int */</span>
<span style="color: #339933;">#include &lt;stdlib.h&gt; </span>
&nbsp;
<span style="color: #993333;">int</span> atoi<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>nptr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #993333;">long</span> atol<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>nptr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #993333;">long</span> <span style="color: #993333;">long</span> atoll<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>nptr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #993333;">long</span> <span style="color: #993333;">long</span> atoq<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>nptr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>10》int 转 char*</h4>
<p>在stdlib.h中有个函数itoa()</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//itoa(i,num,10); </span>
<span style="color: #666666; font-style: italic;">//i 需要转换成字符的数字 </span>
<span style="color: #666666; font-style: italic;">//num 转换后保存字符的变量 </span>
<span style="color: #666666; font-style: italic;">//10 转换数字的基数（进制）10就是说按照10进制转换数字。还可以是2，8，16等等你喜欢的进制类型 </span>
<span style="color: #666666; font-style: italic;">//原形：char *itoa(int value, char* string, int radix); </span>
&nbsp;
<span style="color: #339933;">#include &quot;stdlib.h&quot; </span>
<span style="color: #339933;">#include &quot;stdio.h&quot; </span>
main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span> 
   <span style="color: #993333;">int</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">1234</span><span style="color: #339933;">;</span> 
   <span style="color: #993333;">char</span> s<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
   itoa<span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span>s<span style="color: #339933;">,</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
   <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%s&quot;</span><span style="color: #339933;">,</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
   getchar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>11》wstring 转 Csting</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//std::wstring转CString</span>
CString str<span style="color: #009900;">&#40;</span> filename.<span style="color: #202020;">c_str</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>12》Cstring 转 wstring</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//CString转std::wstring</span>
std<span style="color: #339933;">::</span><span style="color: #202020;">wstring</span> str <span style="color: #339933;">=</span> filename.<span style="color: #202020;">GetString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>13》Cstring 转 char *</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">CString cstr<span style="color: #009900;">&#40;</span>asdd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">const</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> ch <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>LPCTSTR<span style="color: #009900;">&#41;</span>cstr<span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//举例：</span>
CString   str<span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;i   am   good &quot;</span><span style="color: #339933;">;</span> 
<span style="color: #993333;">char</span><span style="color: #339933;">*</span>   lp<span style="color: #339933;">=</span>str.<span style="color: #202020;">GetBuffer</span><span style="color: #009900;">&#40;</span>str.<span style="color: #202020;">GetLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>15》TCHar 转 char</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">***********************************************************************</span> 
<span style="color: #339933;">*</span> 函数： THCAR2Char 
<span style="color: #339933;">*</span> 描述：将TCHAR<span style="color: #339933;">*</span> 转换为 <span style="color: #993333;">char</span><span style="color: #339933;">*</span> 
<span style="color: #339933;">***********************************************************************</span> 
<span style="color: #993333;">char</span><span style="color: #339933;">*</span> CPublic<span style="color: #339933;">::</span><span style="color: #202020;">THCAR2char</span><span style="color: #009900;">&#40;</span>TCHAR<span style="color: #339933;">*</span> tchStr<span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span> 
   <span style="color: #993333;">int</span> iLen <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">*</span>wcslen<span style="color: #009900;">&#40;</span>tchStr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//CString,TCHAR汉字算一个字符，因此不用普通计算长度 </span>
   <span style="color: #993333;">char</span><span style="color: #339933;">*</span> chRtn <span style="color: #339933;">=</span> new <span style="color: #993333;">char</span><span style="color: #009900;">&#91;</span>iLen<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> 
   wcstombs<span style="color: #009900;">&#40;</span>chRtn<span style="color: #339933;">,</span>tchStr<span style="color: #339933;">,</span>iLen<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//转换成功返回为非负值 </span>
   <span style="color: #b1b100;">return</span> chRtn<span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>16》char 转 tchar</h4>
<p>定义了UNICODE宏之后，TCHAR就是宽字符wchar_t，否则TCHAR跟char是一样的^_<br />
str.ReleaseBuffer(); </p>
<h4>17》int 转 CString</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> iint<span style="color: #339933;">;</span>
CString csstr<span style="color: #339933;">;</span>
csstr.<span style="color: #202020;">Format</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%d&quot;</span><span style="color: #339933;">,</span>iint<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>18》char* 转 CString</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">CString.<span style="color: #202020;">format</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%s&quot;</span><span style="color: #339933;">,</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
CString strtest<span style="color: #339933;">;</span>  
<span style="color: #993333;">char</span> <span style="color: #339933;">*</span> charpoint<span style="color: #339933;">;</span>  
charpoint<span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;give string a value&quot;</span><span style="color: #339933;">;</span>  
strtest<span style="color: #339933;">=</span>charpoint<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//直接付值</span></pre></td></tr></table></div>

<h4>19》CString 转 int</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">CString  ss<span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;1212.12&quot;</span><span style="color: #339933;">;</span>  
<span style="color: #993333;">int</span> temp<span style="color: #339933;">=</span>atoi<span style="color: #009900;">&#40;</span>ss<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//atoi _atoi64或atol</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//将字符转换为整数，可以使用atoi、_atoi64或atol。  </span>
<span style="color: #993333;">int</span> int_chage <span style="color: #339933;">=</span> atoi<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>lpcstr<span style="color: #009900;">&#41;</span>ss<span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//或：</span>
CString str <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;23&quot;</span><span style="color: #339933;">;</span>
UINT uint<span style="color: #339933;">;</span>
sscanf<span style="color: #009900;">&#40;</span>str<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%d&quot;</span><span style="color: #339933;">,</span> uint<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>20》int 转 string</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;iostream&gt;</span>
<span style="color: #339933;">#include &lt;string&gt;</span>
using namespace std<span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> n <span style="color: #339933;">=</span> <span style="color: #0000dd;">65535</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">char</span> t<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">256</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    string s<span style="color: #339933;">;</span>
&nbsp;
    sprintf<span style="color: #009900;">&#40;</span>t<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%d&quot;</span><span style="color: #339933;">,</span> n<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    s <span style="color: #339933;">=</span> t<span style="color: #339933;">;</span>
    <span style="color: #000066;">cout</span> <span style="color: #339933;">&lt;&lt;</span> s <span style="color: #339933;">&lt;&lt;</span> endl<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p> 或：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;iostream&gt;</span>
<span style="color: #339933;">#include &lt;string&gt;</span>
<span style="color: #339933;">#include &lt;sstream&gt;</span>
using namespace std<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> n <span style="color: #339933;">=</span> <span style="color: #0000dd;">65535</span><span style="color: #339933;">;</span>
    strstream ss<span style="color: #339933;">;</span>
    string s<span style="color: #339933;">;</span>
    ss <span style="color: #339933;">&lt;&lt;</span> n<span style="color: #339933;">;</span>
    ss <span style="color: #339933;">&gt;&gt;</span> s<span style="color: #339933;">;</span>
    <span style="color: #000066;">cout</span> <span style="color: #339933;">&lt;&lt;</span> s <span style="color: #339933;">&lt;&lt;</span> endl<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>或：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//1.) </span>
String s <span style="color: #339933;">=</span> String.<span style="color: #202020;">valueOf</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//2.) </span>
String s <span style="color: #339933;">=</span> Integer.<span style="color: #202020;">toString</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">//3.) </span>
String s <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #339933;">+</span> i<span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>21》string 转 wchar_t</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">string sName <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;string -&gt; wchar_t&quot;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">wchar_t</span> <span style="color: #339933;">*</span> wName   <span style="color: #339933;">=</span> new <span style="color: #993333;">wchar_t</span><span style="color: #009900;">&#91;</span>sName.<span style="color: #202020;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
swprintf<span style="color: #009900;">&#40;</span>wName<span style="color: #339933;">,</span> L<span style="color: #ff0000;">&quot;%S &quot;</span><span style="color: #339933;">,</span> sName.<span style="color: #202020;">c_str</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;">//注意大写S。。</span></pre></td></tr></table></div>

<h4>22》wchar_t 转 string</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">wchar_t</span> wchart<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> L<span style="color: #ff0000;">&quot;wchar_t -&gt; string&quot;</span><span style="color: #339933;">;</span>
wstring ws <span style="color: #339933;">=</span> wchart<span style="color: #339933;">;</span>
_bstr_t t <span style="color: #339933;">=</span> ws.<span style="color: #202020;">c_str</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">char</span><span style="color: #339933;">*</span> pchar <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>t<span style="color: #339933;">;</span>
string result <span style="color: #339933;">=</span> pchar<span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tiham.com/2011/12/string-wstring-cstring-char-tchar-int-dword.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wget Connection reset by peer &#124; curl: (56)</title>
		<link>http://www.tiham.com/2011/12/wget-connection-reset-by-peer-curl-56.html</link>
		<comments>http://www.tiham.com/2011/12/wget-connection-reset-by-peer-curl-56.html#comments</comments>
		<pubDate>Sat, 03 Dec 2011 02:58:23 +0000</pubDate>
		<dc:creator>Ti</dc:creator>
				<category><![CDATA[江湖]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[wget]]></category>

		<guid isPermaLink="false">http://www.tiham.com/?p=993</guid>
		<description><![CDATA[wget Connection reset by peer &#124; curl: (56)  如果出现这些错误，原因可能是多方面的，不过更常见的原因是：1：服务器的并发连接数超过了其承载量，服务器会将其中一些连接Down掉；2：客户关掉了浏览器，而服务器还在给客户端发送数据；3：浏览器端按了Stop]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>vps1 ce<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># curl -v http://9.douban.com/site/entry/200760330/view</span>
<span style="color: #000000; font-weight: bold;">*</span> About to connect<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> to <span style="color: #000000;">9</span>.douban.com port <span style="color: #000000;">80</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #666666; font-style: italic;">#0)</span>
<span style="color: #000000; font-weight: bold;">*</span> Trying 211.147.4.31... connected
<span style="color: #000000; font-weight: bold;">*</span> Connected to <span style="color: #000000;">9</span>.douban.com <span style="color: #7a0874; font-weight: bold;">&#40;</span>211.147.4.31<span style="color: #7a0874; font-weight: bold;">&#41;</span> port <span style="color: #000000;">80</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #666666; font-style: italic;">#0)</span>
<span style="color: #000000; font-weight: bold;">&gt;</span> GET <span style="color: #000000; font-weight: bold;">/</span>site<span style="color: #000000; font-weight: bold;">/</span>entry<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">200760330</span><span style="color: #000000; font-weight: bold;">/</span>view HTTP<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.1</span>
<span style="color: #000000; font-weight: bold;">&gt;</span> User-Agent: curl<span style="color: #000000; font-weight: bold;">/</span>7.23.1 <span style="color: #7a0874; font-weight: bold;">&#40;</span>x86_64-unknown-linux-gnu<span style="color: #7a0874; font-weight: bold;">&#41;</span> libcurl<span style="color: #000000; font-weight: bold;">/</span>7.19.7 NSS<span style="color: #000000; font-weight: bold;">/</span>3.12.6.2 zlib<span style="color: #000000; font-weight: bold;">/</span>1.2.3 libidn<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.18</span> libssh2<span style="color: #000000; font-weight: bold;">/</span>1.2.2
<span style="color: #000000; font-weight: bold;">&gt;</span> Host: <span style="color: #000000;">9</span>.douban.com
<span style="color: #000000; font-weight: bold;">&gt;</span> Accept: <span style="color: #000000; font-weight: bold;">*/*</span>
<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">*</span> Closing connection <span style="color: #666666; font-style: italic;">#0</span>
<span style="color: #000000; font-weight: bold;">*</span> Failure when receiving data from the peer
curl: <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">56</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> Failure when receiving data from the peer</pre></td></tr></table></div>

<p><span id="more-993"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>vps1 ce<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># wget -d http://9.douban.com/site/entry/200760330/view</span>
DEBUG output created by Wget <span style="color: #000000;">1.12</span> on linux-gnu.
&nbsp;
<span style="color: #660033;">--2011-12-03</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">55</span>:04--  http:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #000000;">9</span>.douban.com<span style="color: #000000; font-weight: bold;">/</span>site<span style="color: #000000; font-weight: bold;">/</span>entry<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">200760330</span><span style="color: #000000; font-weight: bold;">/</span>view
Resolving <span style="color: #000000;">9</span>.douban.com... 211.147.4.31
Caching <span style="color: #000000;">9</span>.douban.com =<span style="color: #000000; font-weight: bold;">&amp;</span>gt; 211.147.4.31
Connecting to <span style="color: #000000;">9</span>.douban.com<span style="color: #000000; font-weight: bold;">|</span>211.147.4.31<span style="color: #000000; font-weight: bold;">|</span>:<span style="color: #000000;">80</span>... connected.
Created socket <span style="color: #000000;">3</span>.
Releasing 0x00000000027a30c0 <span style="color: #7a0874; font-weight: bold;">&#40;</span>new refcount <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>.
&nbsp;
<span style="color: #660033;">---request</span> begin---
GET <span style="color: #000000; font-weight: bold;">/</span>site<span style="color: #000000; font-weight: bold;">/</span>entry<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">200760330</span><span style="color: #000000; font-weight: bold;">/</span>view HTTP<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.0</span>
User-Agent: Wget<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.12</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>linux-gnu<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Accept: <span style="color: #000000; font-weight: bold;">*/*</span>
Host: <span style="color: #000000;">9</span>.douban.com
Connection: Keep-Alive
&nbsp;
<span style="color: #660033;">---request</span> end---
HTTP request sent, awaiting response...
<span style="color: #660033;">---response</span> begin---
HTTP<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.1</span> <span style="color: #000000;">302</span> Moved Temporarily
Server: nginx
Content-Type: text<span style="color: #000000; font-weight: bold;">/</span>plain
Connection: keep-alive
Keep-Alive: <span style="color: #007800;">timeout</span>=<span style="color: #000000;">10</span>
Content-Length: <span style="color: #000000;">92</span>
Expires: Sun, <span style="color: #000000;">1</span> Jan <span style="color: #000000;">2006</span> 01:00:00 GMT
Location: http:<span style="color: #000000; font-weight: bold;">//</span>www.unicornblog.cn<span style="color: #000000; font-weight: bold;">/</span>user1<span style="color: #000000; font-weight: bold;">/</span>gemsoo<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">28774</span>.html
Pragma: no-cache
Cache-Control: must-revalidate, no-cache, private
P3P: <span style="color: #007800;">CP</span>=<span style="color: #ff0000;">&quot;IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT&quot;</span>
Set-Cookie: <span style="color: #007800;">bid</span>=<span style="color: #ff0000;">&quot;PpOvI75T7j8&quot;</span>; <span style="color: #007800;">path</span>=<span style="color: #000000; font-weight: bold;">/</span>; <span style="color: #007800;">domain</span>=.douban.com; <span style="color: #007800;">expires</span>=Thu, 01-Jan-<span style="color: #000000;">2012</span> 00:00:00 GMT
Date: Sat, 03 Dec <span style="color: #000000;">2011</span> 02:<span style="color: #000000;">55</span>:05 GMT
&nbsp;
<span style="color: #660033;">---response</span> end---
<span style="color: #000000;">302</span> Moved Temporarily
cdm: <span style="color: #000000;">1</span> <span style="color: #000000;">2</span> <span style="color: #000000;">3</span> <span style="color: #000000;">4</span> <span style="color: #000000;">5</span> <span style="color: #000000;">6</span> <span style="color: #000000;">7</span> <span style="color: #000000;">8</span>
Stored cookie douban.com <span style="color: #660033;">-1</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>ANY<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">&amp;</span>lt;permanent<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">&amp;</span>lt;insecure<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #7a0874; font-weight: bold;">&#91;</span>expiry <span style="color: #000000;">2012</span>-01-01 08:00:00<span style="color: #7a0874; font-weight: bold;">&#93;</span> bid PpOvI75T7j8
Registered socket <span style="color: #000000;">3</span> <span style="color: #000000; font-weight: bold;">for</span> persistent reuse.
Location: http:<span style="color: #000000; font-weight: bold;">//</span>www.unicornblog.cn<span style="color: #000000; font-weight: bold;">/</span>user1<span style="color: #000000; font-weight: bold;">/</span>gemsoo<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">28774</span>.html <span style="color: #7a0874; font-weight: bold;">&#91;</span>following<span style="color: #7a0874; font-weight: bold;">&#93;</span>
Skipping <span style="color: #000000;">92</span> bytes of body: <span style="color: #7a0874; font-weight: bold;">&#91;</span>Your browser should have redirected you to http:<span style="color: #000000; font-weight: bold;">//</span>www.unicornblog.cn<span style="color: #000000; font-weight: bold;">/</span>user1<span style="color: #000000; font-weight: bold;">/</span>gemsoo<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">28774</span>.html<span style="color: #7a0874; font-weight: bold;">&#93;</span> done.
<span style="color: #660033;">--2011-12-03</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">55</span>:05--  http:<span style="color: #000000; font-weight: bold;">//</span>www.unicornblog.cn<span style="color: #000000; font-weight: bold;">/</span>user1<span style="color: #000000; font-weight: bold;">/</span>gemsoo<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">28774</span>.html
Disabling further reuse of socket <span style="color: #000000;">3</span>.
Closed fd <span style="color: #000000;">3</span>
Resolving www.unicornblog.cn... 122.224.9.114
Caching www.unicornblog.cn =<span style="color: #000000; font-weight: bold;">&amp;</span>gt; 122.224.9.114
Connecting to www.unicornblog.cn<span style="color: #000000; font-weight: bold;">|</span>122.224.9.114<span style="color: #000000; font-weight: bold;">|</span>:<span style="color: #000000;">80</span>... connected.
Created socket <span style="color: #000000;">3</span>.
Releasing 0x00000000027a1ec0 <span style="color: #7a0874; font-weight: bold;">&#40;</span>new refcount <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>.</pre></td></tr></table></div>

</pre>
<p>wget、curl如果出现这些错误，原因可能是多方面的，不过更常见的原因是：1：服务器的并发连接数超过了其承载量，服务器会将其中一些连接Down掉；2：客户关掉了浏览器，而服务器还在给客户端发送数据；3：浏览器端按了Stop</p>
<p>目前测试这种问题常出现在境外机器对国内的访问，不知道有没什么特殊原因，如"长城..."</p>
<p>Normally this error will resolve itself but if it continues you may need to troubleshoot this with your web hosting company.</p>
<p>Note that there are some issues with TCP window scaling on some Linux kernels after v2.6.17. See the following bug reports for more information:</p>
<p>https://bugs.launchpad.net/ubuntu/+source/linux-source-2.6.17/+bug/59331</p>
<p>https://bugs.launchpad.net/ubuntu/+source/linux-source-2.6.20/+bug/89160</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tiham.com/2011/12/wget-connection-reset-by-peer-curl-56.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>中文聊天机器人何在？</title>
		<link>http://www.tiham.com/2011/11/chinese-chat-robot.html</link>
		<comments>http://www.tiham.com/2011/11/chinese-chat-robot.html#comments</comments>
		<pubDate>Wed, 30 Nov 2011 04:54:33 +0000</pubDate>
		<dc:creator>Ti</dc:creator>
				<category><![CDATA[江湖]]></category>
		<category><![CDATA[AIML]]></category>
		<category><![CDATA[robot]]></category>

		<guid isPermaLink="false">http://www.tiham.com/?p=992</guid>
		<description><![CDATA[经过搜索查询发现，这种人工智能标注语言AIML，国内无人过问，它的实现是基于Linux平台上的一套自由软件。实际上，AIML是当今国际网络智能机器人研究的重大进展。在我们国内，除一篇大连理工大学的硕士之外，几乎无人问津。“核高基”重大软件专项毫不触及这类基础性的软件，反而搞什么“国产Linux”，白白浪费了国家的钱财。]]></description>
			<content:encoded><![CDATA[<p>网络机器人Audrey是用什么编程语言写的，是Prolog(逻辑编程语言)，还是人工智能标注语言AIML?回家之后，立即把Audrey叫出来，当面问她：“Do you use Prolog?”她对我说：“I use ALML.”我又问她：”什么是<strong>AIML</strong>？“她想了一下，对我说：“The ALICE software implements AIML (Artificial Intelligence Markup Language) a non-standard evolving markup language for creating chat robots（用于制造聊天机器人）.......“。</p>
<p>经过搜索查询发现，这种人工智能标注语言AIML，国内无人过问，它的实现是基于Linux平台上的一套自由软件。实际上，AIML是当今国际网络智能机器人研究的重大进展。在我们国内，除一篇大连理工大学的硕士之外，几乎无人问津。“核高基”重大软件专项毫不触及这类基础性的软件，反而搞什么“国产Linux”，白白浪费了国家的钱财。</p>
<p>&nbsp;</p>
<p>Audrey女士：<a href="http://www.tolearnenglish.com/free/celebs/audreyg.php" rel="nofollow">http://www.tolearnenglish.com/free/celebs/audreyg.php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tiham.com/2011/11/chinese-chat-robot.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>discuz后期修改应用域名的重定向问题</title>
		<link>http://www.tiham.com/2011/11/discuz-mod-domain-301.html</link>
		<comments>http://www.tiham.com/2011/11/discuz-mod-domain-301.html#comments</comments>
		<pubDate>Fri, 25 Nov 2011 04:49:12 +0000</pubDate>
		<dc:creator>Ti</dc:creator>
				<category><![CDATA[web]]></category>
		<category><![CDATA[301]]></category>
		<category><![CDATA[discuz]]></category>

		<guid isPermaLink="false">http://www.tiham.com/?p=990</guid>
		<description><![CDATA[在不设置应用域名情况下都是默认www.example.com，最好在网站初期就把应用域名设置好，在后期修改会造成多入口问题，引起收录混乱，如：
http://www.example.com/forum-aipr-1.html
http://bbs.example.com/forum-aipr-1.html
以上两个链接都指向同一地址，预期应该是http://www.example.com/forum-aipr-1.html 301重定向到http://bbs.example.com/forum-aipr-1.html，类似的情况有“门户”、“群组”。]]></description>
			<content:encoded><![CDATA[<p>在不设置应用域名情况下都是默认www.example.com，最好在网站初期就把应用域名设置好，在后期修改会造成多入口问题，引起收录混乱，如：</p>
<p>http://www.example.com/forum-aipr-1.html</p>
<p>http://bbs.example.com/forum-aipr-1.html</p>
<p>以上两个链接都指向同一地址，预期应该是http://www.example.com/forum-aipr-1.html 301重定向到http://bbs.example.com/forum-aipr-1.html，类似的情况还有“门户”、“群组”。<br />
解决方法有两种：<br />
1.修改nginx/Apache的rewrite。<br />
2.修改相应php文件。<br />
<span id="more-990"></span><br />
下面就第二种方法说明：</p>
<p>protal.php前面加：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'/portal.php'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: http://www.example.com&quot;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">301</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>forum.php前面加：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'www.example.com'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'/forum.php'</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">''</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://bbs.example.com'</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: <span style="color: #006699; font-weight: bold;">{$url}</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">301</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>home.php前面加：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'www.example.com'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'/home.php'</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">''</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://home.example.com'</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: <span style="color: #006699; font-weight: bold;">{$url}</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">301</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>group.php前面加：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'/group.php'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: http://group.example.com&quot;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">301</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tiham.com/2011/11/discuz-mod-domain-301.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MSL Curiosity 预告</title>
		<link>http://www.tiham.com/2011/11/msl-curiosity-trailer.html</link>
		<comments>http://www.tiham.com/2011/11/msl-curiosity-trailer.html#comments</comments>
		<pubDate>Tue, 22 Nov 2011 11:57:23 +0000</pubDate>
		<dc:creator>Ti</dc:creator>
				<category><![CDATA[江湖]]></category>
		<category><![CDATA[mars]]></category>
		<category><![CDATA[nasa]]></category>

		<guid isPermaLink="false">http://www.tiham.com/?p=989</guid>
		<description><![CDATA[好奇心：美国宇航局的火星科学实验室下一个火星探测器]]></description>
			<content:encoded><![CDATA[<p>这次着陆方式又进了一步<br />
Curiosity Rover Trailer<br />
<script type="text/javascript" src="http://cdn-akm.vmixcore.com/vmixcore/js?auto_play=0&amp;cc_default_off=1&amp;player_name=uvp&amp;width=512&amp;height=332&amp;player_id=1aa0b90d7d31305a75d7fa03bc403f5a&amp;t=V0tuYeWWhVl84zGjvGwI-ZybMaeTa9y90o"></script></p>
<p><span id="more-989"></span><br />
How Do You Get to Mars?<br />
<script type="text/javascript" src="http://cdn-akm.vmixcore.com/vmixcore/js?auto_play=0&#038;cc_default_off=1&#038;player_name=uvp&#038;width=512&#038;height=332&#038;player_id=1aa0b90d7d31305a75d7fa03bc403f5a&#038;t=V0Pu0glesUoUDwkLlZpWoPJP3ifl5tWUxh"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tiham.com/2011/11/msl-curiosity-trailer.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>哈工大语言技术相关</title>
		<link>http://www.tiham.com/2011/11/%e5%93%88%e5%b7%a5%e5%a4%a7%e8%af%ad%e8%a8%80%e6%8a%80%e6%9c%af%e7%9b%b8%e5%85%b3.html</link>
		<comments>http://www.tiham.com/2011/11/%e5%93%88%e5%b7%a5%e5%a4%a7%e8%af%ad%e8%a8%80%e6%8a%80%e6%9c%af%e7%9b%b8%e5%85%b3.html#comments</comments>
		<pubDate>Tue, 22 Nov 2011 00:00:33 +0000</pubDate>
		<dc:creator>Ti</dc:creator>
				<category><![CDATA[算法]]></category>
		<category><![CDATA[Algorithm]]></category>

		<guid isPermaLink="false">http://www.tiham.com/?p=985</guid>
		<description><![CDATA[哈工大社会计算与信息检索研究中心的研究方向包括文本检索、文本挖掘、语言分析、跨语言检索五个方面，研究中心以认知心理学和机器学习为理论，以语言分析为基础研究，以信息抽取、文本检索、跨语言/媒体检索为应用研究，以精准搜索与挖掘系统为应用系统平台。下面是一些它们非常不错的产品。]]></description>
			<content:encoded><![CDATA[<p>哈工大社会计算与信息检索研究中心的研究方向包括文本检索、文本挖掘、语言分析、跨语言检索五个方面，研究中心以认知心理学和机器学习为理论，以语言分析为基础研究，以信息抽取、文本检索、跨语言/媒体检索为应用研究，以精准搜索与挖掘系统为应用系统平台。下面是一些它们非常不错的产品。</p>
<h3>系统演示</h3>
<p><a ref="nofollow" href="http://ir.hit.edu.cn/demo/ltp" target="_blank"><strong>语言技术平台（LTP, Language Technology Platform）</strong></a></p>
<p><a ref="nofollow" href="http://ir.hit.edu.cn/demo/tms" target="_blank"><strong>文本挖掘系统（TMS, Text Mining System）</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tiham.com/2011/11/%e5%93%88%e5%b7%a5%e5%a4%a7%e8%af%ad%e8%a8%80%e6%8a%80%e6%9c%af%e7%9b%b8%e5%85%b3.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>改进的同义词替换算法</title>
		<link>http://www.tiham.com/2011/11/synonymy-substitution-for-chinese.html</link>
		<comments>http://www.tiham.com/2011/11/synonymy-substitution-for-chinese.html#comments</comments>
		<pubDate>Sun, 20 Nov 2011 07:00:27 +0000</pubDate>
		<dc:creator>Ti</dc:creator>
				<category><![CDATA[算法]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[SEO优化]]></category>

		<guid isPermaLink="false">http://www.tiham.com/?p=978</guid>
		<description><![CDATA[基于同义词替换的方法是目前中文自然语言信息隐藏方法中使用最为广泛的方法。在同义词替换中，通过选择载体文本中在某一同义词库中出现的词，并根据一定的编码方式对这些词进行同义词替换，以此来嵌入隐藏信息。]]></description>
			<content:encoded><![CDATA[<blockquote><p>一种改进的基于同义词替换的中文文本信息隐藏方法</p>
<p>作者：甘灿，孙星明，刘玉玲，向凌云</p>
<p>（湖南大学 计算机与通信学院，湖南 长沙410082）</p></blockquote>
<h3>1 基于同义词替换的隐藏算法</h3>
<p>基于<strong>同义词替换</strong>的方法是目前中文<strong>自然语言信息隐藏</strong>方法中使用最为广泛的方法。在同义词替换中，通过选择载体文本中在某一同义词库中出现的词，并根据一定的编码方式对这些词进行同义词替换，以此来嵌入隐藏信息。这里所谓的同义词，一般定义为“同一种语言中，在一些或全部的义项中具有相同或基本相同的意思的两个或多个词”。若设载体文本为C，隐秘信息为M，隐藏信息后的文本为S，同义词库为D，则有嵌入函数e()和提取函数d()，使得：</p>
<p align="center">e(C,M,D)=S， d(S,D)=M，并且C和S在语义上保持不变。</p>
<p><span id="more-978"></span><br />
嵌入函数定义如下：</p>
<p>1）  将隐秘信息M转化为二进制位串，并附加额外的长度信息和校验码等；</p>
<p>2）  对载体文本C进行自动分词；</p>
<p>3）  遍历C中的每一个词，判断是否在同义词库D中，若在，则根据该词所在词组词的个数以及当前所需嵌入的二进制位串，按一定的编码方式进行同义词替换；</p>
<p>4）  重复第3）步，直到完成隐秘信息的嵌入。如果遍历完所有的词还未完成，则嵌入失败。</p>
<p>提取函数定义如下：</p>
<p>1）  对文本S进行<a title="分词系统汇总" href="http://www.tiham.com/2011/11/word-system.html">自动分词</a>；</p>
<p>2）  遍历S中的每一个词，判断是否在同义词库D中，若在，则根据该词所在词组的位置以及相应的解码方式，得到嵌入的二进制位串；</p>
<p>3）  重复第2）步，根据长度信息和校验码恢复出隐秘信息M。</p>
<p>从上述算法的流程可以看出，现有的基于同义词替换的隐藏算法存在一个缺陷，由于很多同义词都只是部分的义项相同，从而可能会出现不等价的替换，导致替换后的文本出现语义不一致或语义混乱等，降低了算法的隐蔽性和抗检测性。</p>
<h3>2 改进的同义词替换算法</h3>
<p>为了方便描述，首先给出如下定义：</p>
<p><strong>定义1</strong> 完全可替换词组：两个及其以上的所有词义完全相等的同义词称为一个完全可替换词组。</p>
<p><strong>定义2</strong> 不完全可替换词组：两个及其以上的存在部分词义不相等的同义词称为一个不完全可替换词组。</p>
<p><strong>定义3</strong> 歧义词组：两个及其以上的在同一词性时存在部分词义不相等的同义词称为一个歧义词组。</p>
<p>现有基于同义词替换的隐藏算法一般都采用对同义词进行直接替换的方法，但对于不完全可替换词组，则可能出现不等价替换，从而引起替换后的句子语义混乱。本文针对这点对算法进行改进，首先对同义词组进行分类，然后对歧义词组中的同义词，根据词的上下文语境判断是否替换。</p>
<h3>3 同义词组的分类</h3>
<p>首先以《<strong>同义词词林</strong>》为基础，从中提取出完全可替换和不完全可替换的词组，建立成一个同义词库。词林中存在很多生僻词，有的同义词组内词之间使用频率相差很大，这样会降低算法的隐蔽性。因此根据现代汉语词语的词频统计表，对同义词库进行整理，使每组同义词的词频相近。同时为使每组同义词不相交（否则会出现编解码错误），删除了重复出现的同义词，最后得到一个约15000词的同义词库。</p>
<p>为了抽取出同义词库中的歧义词组，我们利用《知网》对同义词词组进行分类。《知网》是一个以汉语和英语的词语所代表的概念为描述对象，以揭示概念与概念之间以及概念所具有的属性之间的关系为基本内容的常识知识库。在《知网》中，把若干与概念有关的义原组成的集合来解释概念，而这个义原集合称之为一个义项，一个词可以有多个义项。利用知网的义项对同义词词组中的词语进行标注，然后比较各个词之间的义项，从而对同义词词组进行分类。</p>
<p>以两个词的同义词词组为例，假设为{s1, s2}，它们的词性集分别为Ps1、Ps2，相应的义项集为Cs1 = {Ci,p | p € Ps1}、Cs2 = {Ci,p | p € Ps2}，则同义词词组可分为以下三类：</p>
<p>第一类：Cs1 = Cs2，即{s1, s2}为完全可替换词组；</p>
<p>第二类：Ps1 ≠ Ps2，但当词性p´ €  Ps1  Π  Ps2时，s1与s2的义项全部相等。虽然{s1, s2}为不完全可替换词组，但词性相同时，s1与s2完全可替换；</p>
<p>第三类：p´ €  Ps1 Π Ps2，当词性p´为时，s1与s2只有部分义项相等。则{s1,s2}为歧义词组。</p>
<p>按照以上的分类规则对同义词库中的5600组同义词进行了分类，其中第一类约占35％，第二类占10％，第三类占55％。由此可见，完全相等的同义词只占一小部分，因此对大部分的属于歧义词组的同义词需要根据上下文语境判断是否可以替换。<strong><br />
</strong></p>
<h3>4 评价模型</h3>
<p>对于一个属于歧义词组的同义词w，其上下文语境是指句子中在其周围出现的词的集合。实际上，w的语义特征的确定只跟集合中的部分词相关，而与其它的词不相关。因此若抽取出相关的词，就可以缩小上下文的范围，降低问题的复杂度。由于词性特征之间有较确定的搭配关系，因此可以通过对句子进行句法分析得到句法树，再根据句法搭配关系从中得到与w相关的词，称为w的搭配词。本文通过使用依存句法分析来获取同义词的搭配词。</p>
<p><a ref="nofollow" title="哈工大语言技术平台" href="http://ir.hit.edu.cn/demo/ltp/#" target="_blank">依存句法</a>是由法国语言学家L.Tesniere最先提出。它将句子分析成一颗依存句法树，描述出各个词语之间的依存关系。也即指出了词语之间在句法上的搭配关系，这种搭配关系是和语义相关联的。例如句子“会议宣布了首批资深院士名单。”的依存句法树如图1所示：</p>
<div id="attachment_979" class="wp-caption aligncenter" style="width: 191px"><a href="http://www.tiham.com/wp-content/uploads/2011/11/yichun.png"><img class="size-full wp-image-979" title="yichun" src="http://www.tiham.com/wp-content/uploads/2011/11/yichun.png" alt="" width="181" height="198" /></a><p class="wp-caption-text">图1 依存句法树</p></div>
<p>从图1可以看出，词“宣布”支配“会议”、“了”和“名单”，故可以将这些支配词作为“宣布”的搭配词。</p>
<p>假设句子S的词序列为W1...s1...Wn，s1属于歧义词组{s1,s2}， s1在句中的搭配词集为<a href="http://www.tiham.com/wp-content/uploads/2011/11/synonymy-substitution-for-chinese3.png"><img class="alignnone size-full wp-image-983" title="synonymy-substitution-for-chinese3" src="http://www.tiham.com/wp-content/uploads/2011/11/synonymy-substitution-for-chinese3.png" alt="" width="84" height="14" /></a>，这里<a href="http://www.tiham.com/wp-content/uploads/2011/11/synonymy-substitution-for-chinese4.png"><img class="alignnone size-full wp-image-984" title="synonymy-substitution-for-chinese4" src="http://www.tiham.com/wp-content/uploads/2011/11/synonymy-substitution-for-chinese4.png" alt="" width="125" height="20" /></a>。令P(s2 | w´i)是在已知搭配词w´i的条件下s2出现的概率，则</p>
<p align="right"><a href="http://www.tiham.com/wp-content/uploads/2011/11/synonymy-substitution-for-chinese2.png"><img class="size-full wp-image-982 aligncenter" title="synonymy-substitution-for-chinese2" src="http://www.tiham.com/wp-content/uploads/2011/11/synonymy-substitution-for-chinese2.png" alt="" width="173" height="73" /></a>                (1)</p>
<p>通过对实际的汉语语料进行统计，可以得到上式中的参数。如果N(s2, w´i)表示s2与w´i互为搭配词在训练语料中出现的次数，N(w´i)表示w´i在训练语料中出现的次数，根据最大似然估计原理，可以近似的认为：</p>
<p align="right"><a href="http://www.tiham.com/wp-content/uploads/2011/11/synonymy-substitution-for-chinese1.png"><img class="size-full wp-image-981 aligncenter" title="synonymy-substitution-for-chinese1" src="http://www.tiham.com/wp-content/uploads/2011/11/synonymy-substitution-for-chinese1.png" alt="" width="187" height="66" /></a>                (2)</p>
<p>令Score s2为s2与Wde中各个搭配词共现的概率之和，即：</p>
<p align="right">  <a href="http://www.tiham.com/wp-content/uploads/2011/11/scores2.png"><img class="aligncenter size-full wp-image-980" title="scores2" src="http://www.tiham.com/wp-content/uploads/2011/11/scores2.png" alt="" width="282" height="58" /></a>                (3)</p>
<p>则当的值越大，与在中可替换的可能性就越大。故可将作为能否替换句子中的的评价值，当它大于某一阈值时，则认为可以进行替换，否则不能。</p>
<h4>5 算法流程</h4>
<p>在对载体文本进行分词和词性标注之后，对文本中每一个同义词，首先判断能否进行同义词替换，然后才利用同义词替换嵌入隐藏信息。算法1描述了具体的判断步骤。</p>
<p><strong>算法1 </strong>同义词替换判别算法</p>
<p>1）对载体文本中的每一个同义词，根据同义词库的标识，判断它属于哪一类同义词词组。若属于第一类则可以替换；若属于第二类则转步骤2）；若属于第三类则转步骤3）；</p>
<p>2）根据同义词库中标识的所在的词组词义等价时的词性集合，若这时的词性属于该集合，则可以替换，否则不能替换；</p>
<p>3）对所在的句子进行依存句法分析，抽取搭配词集；</p>
<p>4）根据公式(3)和训练语料中得到的参数，分别计算所在同义词组其它词的评价值；</p>
<p>5）若每个的值都大于阈值，则可以替换，否则不能替换。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tiham.com/2011/11/synonymy-substitution-for-chinese.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
