<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[通过C++来自动配置Host文件来访问域名来学习C++如何读取和修改文件]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Fri, 24 Dec 2010 11:18:52 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	<br/><div class="code">#include &lt;iostream&gt;<br/>#include &lt;fstream&gt;<br/>using namespace std;<br/>#ifdef WIN32<br/>#define TEST_FILE &quot;C:&#92;&#92;WINDOWS&#92;&#92;system32&#92;&#92;drivers&#92;&#92;etc&#92;&#92;hosts&quot;<br/>#else<br/>#define TEST_FILE &quot;/etc/hosts&quot;<br/>#endif<br/>char *flagstr = &quot;discuz.addev.com&quot;;<br/>int needModify = 1;<br/>const char buf&#91;&#93; = &quot;172.25.38.70&nbsp;&nbsp;&nbsp;&nbsp;discuz.addev.com&quot;;<br/>void checkHostExist()<br/>&#123;<br/>&nbsp;&nbsp;ifstream fin(TEST_FILE); <br/>&nbsp;&nbsp;string str; <br/>&nbsp;&nbsp;while(getline(fin,str))<br/>&nbsp;&nbsp;&#123; <br/>&nbsp;&nbsp;char *pos = strstr(str.c_str(),flagstr);&nbsp;&nbsp; <br/>&nbsp;&nbsp;if (pos != NULL) <br/>&nbsp;&nbsp;&#123; <br/>&nbsp;&nbsp;&nbsp;&nbsp;//检查是否包好 #<br/>&nbsp;&nbsp;&nbsp;&nbsp; char *poscheck = strstr(str.c_str(),&quot;#&quot;); <br/>&nbsp;&nbsp;&nbsp;&nbsp;if (poscheck == NULL) //没有# <br/>&nbsp;&nbsp;&nbsp;&nbsp;&#123;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;needModify = 0;//没有#号就不需要添加 <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&#125; <br/>&#125; <br/><br/><br/>&#125;<br/><br/>void test()<br/>&#123;<br/>&nbsp;&nbsp;ofstream ofs(TEST_FILE,ios_base::app);<br/>&nbsp;&nbsp;cout &lt;&lt; TEST_FILE;<br/>&nbsp;&nbsp;char ch = &#039;&#92;n&#039;;<br/>&nbsp;&nbsp;ofs.put(ch);//simple<br/>&nbsp;&nbsp;ofs.write(buf, sizeof(buf));<br/>&nbsp;&nbsp;ofs.close();<br/>&#125;<br/>int main(int argc, char* argv&#91;&#93;)<br/>&#123;<br/>&nbsp;&nbsp;checkHostExist();<br/>&nbsp;&nbsp;if(1 == needModify)<br/>&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;test();&nbsp;&nbsp;//需要加入host，添加进入，否则不用添加，直接打开浏览器 <br/>&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;//浏览器直接打开 <br/>&nbsp;&nbsp;system(&quot;&#92;&quot;C:&#92;&#92;Program Files&#92;&#92;Internet Explorer&#92;&#92;IEXPLORE.EXE&#92;&quot; http://discuz.addev.com&quot;);<br/>&nbsp;&nbsp;return 0;<br/>&#125;</div><br/><br/><br/>最后，在Linux编译时 出现致命错误 iostream 没有那个文件或目录 编译中断。<br/>你是用g++编译的吗？iostream是c++的头文件，需要使用g++指令而不是gcc。<br/>如果有其他问题请追问，注意要用g++才行，否则会报错错误：iostream：没有那个文件或目录。<br/><textarea name="code" class="c" rows="15" cols="100">
#include &lt;iostream&gt;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
using namespace std;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
int main()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&#123;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;&quot;new machine &quot;&lt;&lt;endl;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;return 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&#125;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</textarea>
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] 通过C++来自动配置Host文件来访问域名来学习C++如何读取和修改文件]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>