﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-michael</title><link>http://www.cppblog.com/michaelgao/</link><description /><language>zh-cn</language><lastBuildDate>Mon, 13 Apr 2026 09:39:29 GMT</lastBuildDate><pubDate>Mon, 13 Apr 2026 09:39:29 GMT</pubDate><ttl>60</ttl><item><title>find number in a gvien S and array</title><link>http://www.cppblog.com/michaelgao/archive/2012/12/10/196141.html</link><dc:creator>micheal's tech</dc:creator><author>micheal's tech</author><pubDate>Mon, 10 Dec 2012 03:38:00 GMT</pubDate><guid>http://www.cppblog.com/michaelgao/archive/2012/12/10/196141.html</guid><wfw:comment>http://www.cppblog.com/michaelgao/comments/196141.html</wfw:comment><comments>http://www.cppblog.com/michaelgao/archive/2012/12/10/196141.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/michaelgao/comments/commentRss/196141.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/michaelgao/services/trackbacks/196141.html</trackback:ping><description><![CDATA[<div></div><p id="" style="margin: 0px 0px 15px; padding: 0px; border: 0px; outline: 0px; font-size: 13px; vertical-align: baseline; color: #222222; font-family: 'Helvetica Neue', arial, sans-serif;">Given an array&nbsp;<em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;">S</em>&nbsp;of&nbsp;<em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;">n</em>&nbsp;integers, are there elements <em>x</em>, <em>y</em>, <em>z</em>&nbsp;in&nbsp;<em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;">S</em>&nbsp;such that&nbsp;<em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;">x</em>&nbsp;+&nbsp;<em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;">y</em>&nbsp;+&nbsp;<em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;">z</em>&nbsp;= 0? Find all unique triplets in the array which gives the sum of zero.</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; outline: 0px; font-size: 13px; vertical-align: baseline; color: #222222; font-family: 'Helvetica Neue', arial, sans-serif;"><strong style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;">Note:</strong><br style="margin: 0px;" /></p><ul style="margin: 0px 0px 0px 40px; padding: 0px; border: 0px; outline: 0px; font-size: 13px; vertical-align: baseline; list-style-position: initial; list-style-image: initial; color: #222222; font-family: 'Helvetica Neue', arial, sans-serif;"><li id="" style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;">Elements in a triplet (<em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;">a</em>,<em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;">b</em>,<em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;">c</em>) must be in non-descending order. (ie,&nbsp;<em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;">a</em>&nbsp;&#8804;&nbsp;<em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;">b</em>&nbsp;&#8804;&nbsp;<em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;">c</em>)</li><li id="aeaoofnhgocdbnbeljkmbjdmhbcokfdb-mousedown" style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;">The solution set must not contain duplicate triplets.<br /><br />一个重要的优化就是如果上个数已经求过集合了 例如[-1 -1 0 2 2]已经包含了[-1 0 2 2] 当然也包含了 [-1 0 2]集合的。</li></ul><div></div><img src ="http://www.cppblog.com/michaelgao/aggbug/196141.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/michaelgao/" target="_blank">micheal's tech</a> 2012-12-10 11:38 <a href="http://www.cppblog.com/michaelgao/archive/2012/12/10/196141.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++ 11 timer callback</title><link>http://www.cppblog.com/michaelgao/archive/2012/12/04/195980.html</link><dc:creator>micheal's tech</dc:creator><author>micheal's tech</author><pubDate>Tue, 04 Dec 2012 10:10:00 GMT</pubDate><guid>http://www.cppblog.com/michaelgao/archive/2012/12/04/195980.html</guid><wfw:comment>http://www.cppblog.com/michaelgao/comments/195980.html</wfw:comment><comments>http://www.cppblog.com/michaelgao/archive/2012/12/04/195980.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/michaelgao/comments/commentRss/195980.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/michaelgao/services/trackbacks/195980.html</trackback:ping><description><![CDATA[<pre prettyprint=""  prettyprinted"="" id="aeaoofnhgocdbnbeljkmbjdmhbcokfdb-mousedown" style="margin-top: 0px; margin-bottom: 10px; padding: 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; overflow: auto; width: auto; max-height: 600px; line-height: 18px;"><div style="font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#include&nbsp;&lt;thread&gt;<br /><br />template&nbsp;&lt;typename&nbsp;Duration,&nbsp;typename&nbsp;Function&gt;<br /><span style="color: #0000FF; ">void</span>&nbsp;timer(Duration&nbsp;<span style="color: #0000FF; ">const</span>&nbsp;&amp;&nbsp;d,&nbsp;Function&nbsp;<span style="color: #0000FF; ">const</span>&nbsp;&amp;&nbsp;f)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;std::thread([d,f](){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::this_thread::sleep_for(d);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f();<br />&nbsp;&nbsp;&nbsp;&nbsp;}).detach();<br />}</div></pre><img src ="http://www.cppblog.com/michaelgao/aggbug/195980.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/michaelgao/" target="_blank">micheal's tech</a> 2012-12-04 18:10 <a href="http://www.cppblog.com/michaelgao/archive/2012/12/04/195980.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>error C2011: 'sockaddr' : 'struct' type redefinition</title><link>http://www.cppblog.com/michaelgao/archive/2012/12/04/195971.html</link><dc:creator>micheal's tech</dc:creator><author>micheal's tech</author><pubDate>Tue, 04 Dec 2012 07:39:00 GMT</pubDate><guid>http://www.cppblog.com/michaelgao/archive/2012/12/04/195971.html</guid><wfw:comment>http://www.cppblog.com/michaelgao/comments/195971.html</wfw:comment><comments>http://www.cppblog.com/michaelgao/archive/2012/12/04/195971.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/michaelgao/comments/commentRss/195971.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/michaelgao/services/trackbacks/195971.html</trackback:ping><description><![CDATA[<span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; background-color: #ffffff;">This problem is caused when including&nbsp;</span><code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; line-height: 18px;">&lt;windows.h&gt;</code><span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; background-color: #ffffff;">&nbsp;before&nbsp;</span><code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; line-height: 18px;">&lt;winsock2.h&gt;</code><span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; background-color: #ffffff;">. Try arrange your include list that&nbsp;</span><code id="" style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; line-height: 18px;">&lt;windows.h&gt;</code><span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; background-color: #ffffff;">&nbsp;is included after&nbsp;</span><code id="" style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; line-height: 18px;">&lt;winsock2.h&gt;</code><span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; background-color: #ffffff;">&nbsp;or define&nbsp;</span><code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; line-height: 18px;">_WINSOCKAPI_</code><span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; background-color: #ffffff;">&nbsp;first:<br /><br />先包含winsock2.h<br />再包含windows.h<br /><br /></span><img src ="http://www.cppblog.com/michaelgao/aggbug/195971.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/michaelgao/" target="_blank">micheal's tech</a> 2012-12-04 15:39 <a href="http://www.cppblog.com/michaelgao/archive/2012/12/04/195971.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>zmq 在类成员中不用指针的方法：</title><link>http://www.cppblog.com/michaelgao/archive/2012/12/03/195928.html</link><dc:creator>micheal's tech</dc:creator><author>micheal's tech</author><pubDate>Mon, 03 Dec 2012 09:51:00 GMT</pubDate><guid>http://www.cppblog.com/michaelgao/archive/2012/12/03/195928.html</guid><wfw:comment>http://www.cppblog.com/michaelgao/comments/195928.html</wfw:comment><comments>http://www.cppblog.com/michaelgao/archive/2012/12/03/195928.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/michaelgao/comments/commentRss/195928.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/michaelgao/services/trackbacks/195928.html</trackback:ping><description><![CDATA[<pre id="aeaoofnhgocdbnbeljkmbjdmhbcokfdb-mousedown" style="line-height: normal;">普通类调用中必须吧zmq设置为指针 否则单纯构造无法初始化<br />直接用初始化列表<br /><br /><div>context(1),netsocket(zmq::socket_t(context, ZMQ_REP))</div><br /></pre><img src ="http://www.cppblog.com/michaelgao/aggbug/195928.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/michaelgao/" target="_blank">micheal's tech</a> 2012-12-03 17:51 <a href="http://www.cppblog.com/michaelgao/archive/2012/12/03/195928.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>费曼学习方法</title><link>http://www.cppblog.com/michaelgao/archive/2012/11/14/195180.html</link><dc:creator>micheal's tech</dc:creator><author>micheal's tech</author><pubDate>Wed, 14 Nov 2012 02:17:00 GMT</pubDate><guid>http://www.cppblog.com/michaelgao/archive/2012/11/14/195180.html</guid><wfw:comment>http://www.cppblog.com/michaelgao/comments/195180.html</wfw:comment><comments>http://www.cppblog.com/michaelgao/archive/2012/11/14/195180.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/michaelgao/comments/commentRss/195180.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/michaelgao/services/trackbacks/195180.html</trackback:ping><description><![CDATA[看见费曼学习方法 我觉得可能管用，最近试一下。<img src ="http://www.cppblog.com/michaelgao/aggbug/195180.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/michaelgao/" target="_blank">micheal's tech</a> 2012-11-14 10:17 <a href="http://www.cppblog.com/michaelgao/archive/2012/11/14/195180.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>dynamic programming</title><link>http://www.cppblog.com/michaelgao/archive/2012/05/17/175176.html</link><dc:creator>micheal's tech</dc:creator><author>micheal's tech</author><pubDate>Thu, 17 May 2012 01:54:00 GMT</pubDate><guid>http://www.cppblog.com/michaelgao/archive/2012/05/17/175176.html</guid><wfw:comment>http://www.cppblog.com/michaelgao/comments/175176.html</wfw:comment><comments>http://www.cppblog.com/michaelgao/archive/2012/05/17/175176.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/michaelgao/comments/commentRss/175176.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/michaelgao/services/trackbacks/175176.html</trackback:ping><description><![CDATA[<h2><span style="font-size: 14pt; "><span style="font-weight: normal;">感觉动态规划中最难的部分是在寻找 从状态j到状态i的递归式，就像证明归纳法一样，你得找出具体的式子来。<br /></span>top bottom<br />bottom up<br />1. Longest Increasing Subsequence:<br /><span style="font-weight: normal;">L[i] = max(1+L(j))(j&lt;l &amp;&amp; a[j]&lt;a[i])</span><br /><span style="font-weight: normal;">//if not exist any a[j]&lt;a[i]</span><br /><span style="font-weight: normal;">L[i] = 1;</span><br /><br /><span style="font-weight: normal;">getmaxvalueof array a[]</span><br /><br /><br /></span><span style="font-size: 14pt; ">2. Maximum Sum Increasing Subsequence<br /><span style="font-weight: normal;">almost same with above</span><br /><br />3. Maximum continous sum<br /><br />4. rod cutting</span></h2><img src ="http://www.cppblog.com/michaelgao/aggbug/175176.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/michaelgao/" target="_blank">micheal's tech</a> 2012-05-17 09:54 <a href="http://www.cppblog.com/michaelgao/archive/2012/05/17/175176.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【外刊IT评论网】你做过的最有效的提高你的编程水平的一件事情是什么</title><link>http://www.cppblog.com/michaelgao/archive/2012/04/17/171700.html</link><dc:creator>micheal's tech</dc:creator><author>micheal's tech</author><pubDate>Tue, 17 Apr 2012 00:40:00 GMT</pubDate><guid>http://www.cppblog.com/michaelgao/archive/2012/04/17/171700.html</guid><wfw:comment>http://www.cppblog.com/michaelgao/comments/171700.html</wfw:comment><comments>http://www.cppblog.com/michaelgao/archive/2012/04/17/171700.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/michaelgao/comments/commentRss/171700.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/michaelgao/services/trackbacks/171700.html</trackback:ping><description><![CDATA[最近在stackexchange网站上看到了一个非常好的问答，有人问：你做过的最有效的提高你的编程水平的一件事情是什么?
回首作为一个程序员这些年来的生活和职业道路，我使用了很多种不同的方法来提高我的编程技能 &#8212;&#8212; 阅读代码，编写程序，阅读书籍，听讲座，看视频，等等。
我的问题是：你做过的最有效的提高你的编程水平的一件事情是什么?对于那些想提高水平的程序员，你的建议是什么？
我希望你们提供的答案是各种各样的，并且不是那种&#8220;放之四海而皆准&#8221;的答案 &#8212;&#8212; 我希望得到适用于不同人的不同的答案。
有很多人给出了自己的答案，在这里，我将其中最受认可的前三种答案选出来翻译给大家。
最受欢迎的回答：学无止境
没有特别的先后次序&#8230;
和比自己更聪明的人一起工作永远乐意听取他人的意见，不管对方是低级水平，一般水平，资深，还是大师。职称头衔并不代表一切。学习其它的框架/语言，学习它们是的工作原理和思想，拿它们跟你已知的技术做比较。学习各种设计模式，最佳实践理论，然后用它们检查自己先前的知识，在需要的时候使用这些模式。结对编程
反对Joel说的一切。
第二受欢迎的回答：成为多面手
争取成为一个&#8216;多面手万事通&#8217;
在我职业生涯的早期，我在一种数据库和编程语言上是个专家。不幸的是，这种数据库在&#8220;数据库战争&#8221;中落败了，我才发现我的职业道路&#8230;很窄。在此之后，我下定决心以后决不能把自己封在一个小空间里。我开始学习所有手头上能接触到的东西：Windows，Unix，C，C++，Java，C#，Perl，Python，Access，SQL Server，Oracle，Informix，MySQL，等等。不管什么样的新的，不常见的工具或技术，我都成为&#8220;大拿&#8221; &#8212;&#8212; &#8220;去问克雷格(作者自己)，他要是不会，他会去学会的。&#8221;结果，我做了各种各样的项目，从为环境监测做嵌入式系统，到为导弹防御做命令和控制系统。
我在各种的公司里唯一遇到的问题是：它们坚持要把我固定在一个专门的研究方向内，而我的专门研究是要成为一个多面手。[编辑：也叫做学识渊博的人或多才多艺的人或多领域专家。]
有些事情需要留意 &#8230; 高科技界里知识的半衰期是多少？根据摩尔定律(Moore&#8217;s law)：18-24月内，半数你学到的知识都会过时。错误的遵循这种规律的专家会轻易的在这种技术发展的压力崩溃；一个多面手要做的事就是不断的丰富自己的技能，并从应用这些技能的经历中吸取教训。
第三受欢迎的回答：不要跟臭棋篓子下棋
我一直认为自己在不错的程序员中也算是个&#8220;灌篮高手&#8221;。直到有个家伙&#8212;&#8212;我们叫他艾伦&#8212;&#8212;被招进团队。艾伦很显然在很多方面都比我优秀。也比我年轻。他让我认识到，在过去的这些年里，我没有多少长进。我是一个特定技术方向的程序员，而且是水平一般。
这惊醒我应该自觉的不断提高自己的水平，特别是我写的代码的水平。
艾伦引导我学会了很多东西。他告诉我，大部分我写的代码在今后的数年里都将一直维护和进行扩展，写代码时要将这点铭记在心。我应该为我的代码写自动测试程序。艾伦说代码的开发一定不能停止在第一版上，应该不断的重构，提炼，让它达到完美。我发现，我对这些语言和工具的使用都还有还很大的改进空间。
从艾伦那我学到的最重要的一件事情是：永远不要停止学习。
数年后，艾伦离开了公司。我的心里突然感觉空荡荡的。这些年与他为伴让我在技能上提升到了一个全新的水平，我知道现在我比团队里的其他人优秀很多。他们仍然写着糟糕的代码，犯着以前犯过的错误。我努力教育他们，但他们对此不感兴趣。事实上，他们讨厌有人这样傲慢自大的指出他们犯的错误。
于是，几个月后，我也离开这这个公司。我去了一个很小的公司，在一个很出色的团队里工作。那里每个人都渴望学习更多知识，我喜欢这样的。
我很幸运能遇到艾伦。没有他，我也许现在仍然待在那家死气沉沉的公司和那帮食古不化的家伙在一起，哪都去不了，想的全是自己的私利。
这个讨论在stackexchange网站上的地址是这里。
从我个人而言，我觉得第三个答案对我最有价值，不知各位同行们有什么感受？请写在评论里与大家分享。
<img src ="http://www.cppblog.com/michaelgao/aggbug/171700.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/michaelgao/" target="_blank">micheal's tech</a> 2012-04-17 08:40 <a href="http://www.cppblog.com/michaelgao/archive/2012/04/17/171700.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>NLP起了 lucene也起了</title><link>http://www.cppblog.com/michaelgao/archive/2012/04/12/171084.html</link><dc:creator>micheal's tech</dc:creator><author>micheal's tech</author><pubDate>Thu, 12 Apr 2012 05:56:00 GMT</pubDate><guid>http://www.cppblog.com/michaelgao/archive/2012/04/12/171084.html</guid><wfw:comment>http://www.cppblog.com/michaelgao/comments/171084.html</wfw:comment><comments>http://www.cppblog.com/michaelgao/archive/2012/04/12/171084.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/michaelgao/comments/commentRss/171084.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/michaelgao/services/trackbacks/171084.html</trackback:ping><description><![CDATA[今天开始记录<img src ="http://www.cppblog.com/michaelgao/aggbug/171084.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/michaelgao/" target="_blank">micheal's tech</a> 2012-04-12 13:56 <a href="http://www.cppblog.com/michaelgao/archive/2012/04/12/171084.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Install package </title><link>http://www.cppblog.com/michaelgao/archive/2009/12/01/102348.html</link><dc:creator>micheal's tech</dc:creator><author>micheal's tech</author><pubDate>Tue, 01 Dec 2009 09:20:00 GMT</pubDate><guid>http://www.cppblog.com/michaelgao/archive/2009/12/01/102348.html</guid><wfw:comment>http://www.cppblog.com/michaelgao/comments/102348.html</wfw:comment><comments>http://www.cppblog.com/michaelgao/archive/2009/12/01/102348.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/michaelgao/comments/commentRss/102348.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/michaelgao/services/trackbacks/102348.html</trackback:ping><description><![CDATA[VS 2008 uninstall package.<br><br><br><br>upgrade code.<br><br><br><br><img src ="http://www.cppblog.com/michaelgao/aggbug/102348.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/michaelgao/" target="_blank">micheal's tech</a> 2009-12-01 17:20 <a href="http://www.cppblog.com/michaelgao/archive/2009/12/01/102348.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How can I run another application or batch file from my Visual C# .NET code?</title><link>http://www.cppblog.com/michaelgao/archive/2009/11/17/101188.html</link><dc:creator>micheal's tech</dc:creator><author>micheal's tech</author><pubDate>Tue, 17 Nov 2009 05:10:00 GMT</pubDate><guid>http://www.cppblog.com/michaelgao/archive/2009/11/17/101188.html</guid><wfw:comment>http://www.cppblog.com/michaelgao/comments/101188.html</wfw:comment><comments>http://www.cppblog.com/michaelgao/archive/2009/11/17/101188.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/michaelgao/comments/commentRss/101188.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/michaelgao/services/trackbacks/101188.html</trackback:ping><description><![CDATA[<h1 class="entryviewheading">How can I run another application or batch file from my Visual C# .NET code?</h1>
<div class="entryviewheadersub"><span class="hiddentext">Published </span>01 June 04 11:54 PM</div>
<p>Posted by: <a  href="http://weblogs.asp.net/duncanma">Duncan Mackenzie</a>, MSDN<br><em>This post applies to Visual&nbsp;C# .NET 2002/2003</em></p>
<p>Suppose you want to run a command line application,&nbsp;open up another
Windows program, or even bring up the default web browser or email
program... <strong>how can you do this from your&nbsp;C# code?</strong></p>
<p>The answer for all of these examples is the same, you can use the classes and methods in <a  href="http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDiagnosticsProcessClassTopic.asp">System.Diagnostics.Process</a> to accomplish these tasks and more.</p>
<p><strong>Example 1.</strong> Running a command line application, without concern for the results:</p>
<pre><span style="font-weight: 400; font-size: 12px; color: #0000ff; font-family: Courier New;">private</span><span> </span><span style="font-weight: 400; font-size: 12px; color: #0000ff; font-family: Courier New;">void</span><span> simpleRun_Click(</span><span style="font-weight: 400; font-size: 12px; color: #0000ff; font-family: Courier New;">object</span><span> sender, System.EventArgs e)</span><span>{<br></span><span>&nbsp;System.Diagnostics.Process.Start(@</span><span style="font-weight: 400; font-size: 12px; color: #ff0000; font-family: Courier New;">"C:\listfiles.bat"</span><span>);<br>}</span></pre>
<p><strong>Example 2.</strong> Retrieving the results and waiting until the process stops (running the process synchronously):</p>
<pre><span style="font-weight: 400; font-size: 12px; color: #0000ff; font-family: Courier New;">private</span><span> </span><span style="font-weight: 400; font-size: 12px; color: #0000ff; font-family: Courier New;">void</span><span> runSyncAndGetResults_Click(</span><span style="font-weight: 400; font-size: 12px; color: #0000ff; font-family: Courier New;">object</span><span> sender, System.EventArgs e){<br>&nbsp;System.Diagnostics.ProcessStartInfo psi =<br> &nbsp;&nbsp;</span><span style="font-weight: 400; font-size: 12px; color: #0000ff; font-family: Courier New;">new</span><span> System.Diagnostics.ProcessStartInfo(@</span><span style="font-weight: 400; font-size: 12px; color: #ff0000; font-family: Courier New;">"C:\listfiles.bat"</span><span>);<br>&nbsp;psi.RedirectStandardOutput = </span><span style="font-weight: 400; font-size: 12px; color: #0000ff; font-family: Courier New;">true</span><span>;<br>&nbsp;psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;<br>&nbsp;psi.UseShellExecute = </span><span style="font-weight: 400; font-size: 12px; color: #0000ff; font-family: Courier New;">false</span><span>;<br>&nbsp;System.Diagnostics.Process listFiles;<br>&nbsp;listFiles = System.Diagnostics.Process.Start(psi);<br>&nbsp;System.IO.StreamReader myOutput = listFiles.StandardOutput;<br>&nbsp;listFiles.WaitForExit(2000);<br>&nbsp;</span><span style="font-weight: 400; font-size: 12px; color: #0000ff; font-family: Courier New;">if</span><span> (listFiles.HasExited)<br> &nbsp;{<br>&nbsp;&nbsp;</span><span style="font-weight: 400; font-size: 12px; color: #0000ff; font-family: Courier New;">string</span><span> output = myOutput.ReadToEnd();<br>&nbsp;&nbsp;</span><span style="font-weight: 400; font-size: 12px; color: #0000ff; font-family: Courier New;">this</span><span>.processResults.Text = output;<br>&nbsp;}<br>}</span></pre>
<p>&nbsp;<strong>Example 3.</strong> Displaying a URL using the default browser on the user's machine:</p>
<pre><span style="font-weight: 400; font-size: 12px; color: #0000ff; font-family: Courier New;">private</span><span> </span><span style="font-weight: 400; font-size: 12px; color: #0000ff; font-family: Courier New;">void</span><span> launchURL_Click(</span><span style="font-weight: 400; font-size: 12px; color: #0000ff; font-family: Courier New;">object</span><span> sender, System.EventArgs e){<br>&nbsp;</span><span style="font-weight: 400; font-size: 12px; color: #0000ff; font-family: Courier New;">string</span><span> targetURL = @</span><span style="font-weight: 400; font-size: 12px; color: #ff0000; font-family: Courier New;"><a  href="http://www.duncanmackenzie.net/">http://www.duncanmackenzie.net</a></span><span>;<br>&nbsp;System.Diagnostics.Process.Start(targetURL);<br>}</span></pre>
<p>In my opinion, you are much better off following the third example
for URLs, as opposed to executing IE with the URL as an argument. The
code shown for Example 3 will launch the user's default browser, which
may or may not be IE; you are more likely to provide the user with the
experience they want and&nbsp;you will be taking advantage of the browser
that is most likely to have up-to-date connection information.</p>
<p><em>C# code download available&nbsp;from <a  href="http://www.duncanmackenzie.net/Samples/default.aspx">http://www.duncanmackenzie.net/Samples/default.aspx</a></em></p>
<p><em>By the way, this post is a simple port of </em><a  href="http://blogs.msdn.com/vbfaq/archive/2004/05/30/144573.aspx"><em>an earlier VB FAQ post</em></a><em>... just in case you thought you had seen it already in your feeds...</em></p><img src ="http://www.cppblog.com/michaelgao/aggbug/101188.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/michaelgao/" target="_blank">micheal's tech</a> 2009-11-17 13:10 <a href="http://www.cppblog.com/michaelgao/archive/2009/11/17/101188.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>