ifstream 读文件后最后会出现乱码.
index.htm
<HTML>
<HEAD><TITLE>internet服务收费标准</TITLE></HEAD>
<pre><H1>internet服务收费标准</H1>
</P>
<hr><form method="POST" action="CHScript.dll">
您要查询的类型是:
<UL><LI>A类用户<input name="usertype" type=radio value="A">
<LI>B类用户<input name="usertype" type=radio value="B">
<LI>C类用户<input name="usertype" type=radio value="C">
<LI>D类用户<input name="usertype" type=radio value="D">
</UL>
<center>
<input type=submit value="提交"> <input type=reset value="取消"></center>
</pre></form><hr>
</HTML>
<HEAD><TITLE>internet服务收费标准</TITLE></HEAD>
<pre><H1>internet服务收费标准</H1>
</P>
<hr><form method="POST" action="CHScript.dll">
您要查询的类型是:
<UL><LI>A类用户<input name="usertype" type=radio value="A">
<LI>B类用户<input name="usertype" type=radio value="B">
<LI>C类用户<input name="usertype" type=radio value="C">
<LI>D类用户<input name="usertype" type=radio value="D">
</UL>
<center>
<input type=submit value="提交"> <input type=reset value="取消"></center>
</pre></form><hr>
</HTML>
// 读取文件
///////////////////////////////////////////////////////////////
void Read(long length = 0)
{
ifstream ifs("index.htm",ios::out | ios::binary);
char *buffer = new char[length];
if(!ifs.eof() && !ifs.fail())
{
ifs.read(buffer, length);
}else{
buffer = NULL;
}
ifs.close();
std::cout<<buffer<<std::endl;
if(buffer)
{
delete [] buffer;
}
}
为什么最后会出现乱码? 是哪里有问题.大家帮我看看...
///////////////////////////////////////////////////////////////
void Read(long length = 0)
{
ifstream ifs("index.htm",ios::out | ios::binary);
char *buffer = new char[length];
if(!ifs.eof() && !ifs.fail())
{
ifs.read(buffer, length);
}else{
buffer = NULL;
}
ifs.close();
std::cout<<buffer<<std::endl;
if(buffer)
{
delete [] buffer;
}
}