问一下大家,看我的代码有什么问题:
i_Count=0;
i_FileCount=0;
ifstream fin("index.html");
while(!m_pRecordset->adoEOF)
{
i_Count++;
var = m_pRecordset->GetCollect("title");
if(var.vt != VT_NULL)
strTitle = _com_util::ConvertBSTRToString((_bstr_t)var); var = m_pRecordset->GetCollect("class");
if(var.vt != VT_NULL)
strClass = _com_util::ConvertBSTRToString((_bstr_t)var); var = m_pRecordset->GetCollect("num");
if(var.vt != VT_NULL)
strNum = _com_util::ConvertBSTRToString((_bstr_t)var); if (i_Count>=20)
{
i_FileCount++;
i_Count=0;
}
m_FileName.Format("indexq[%d].html",i_FileCount);
ofstream fout(m_FileName,ios::app);
string str,str1;
str1=" <p><a href=\"/index.htm\">首页</a> / 新闻</p>";
if(i_Count==1)
{
while (getline (fin, str) )
{
fstream fout(m_FileName,ios::app);
if(fout)
{
fout<<str<<endl;
}
if(0==strcmp(str1.c_str(),str.c_str()) )
{
int m=1;
if(m)
{
ofstream fout(m_FileName,ios::app);
fout<<"<div>"<<endl;
fout<<"<h2>全部新闻</h2>"<<endl;
fout.close();
goto here;
}
}
}
here: fin.close();
}
fout<<strTitle<<"-"<<strClass<<" - "<<strNum<<" <br/>"<<endl;
fout.close();
m_pRecordset->MoveNext();
}
我是希望这个程序从数据库读数据,每20条数据库记录产生一个页面文件,
if(i_Count==1),把一个已有文件内容输入产生的页面文件。可调式的时候,
if(i_Count==1),下面的代码只执行一次不知道为什么?明明i_Count==1了,可他就是不执行下面的代码
请大家帮我看一看什么问题
i_Count=0;
i_FileCount=0;
ifstream fin("index.html");
while(!m_pRecordset->adoEOF)
{
i_Count++;
var = m_pRecordset->GetCollect("title");
if(var.vt != VT_NULL)
strTitle = _com_util::ConvertBSTRToString((_bstr_t)var); var = m_pRecordset->GetCollect("class");
if(var.vt != VT_NULL)
strClass = _com_util::ConvertBSTRToString((_bstr_t)var); var = m_pRecordset->GetCollect("num");
if(var.vt != VT_NULL)
strNum = _com_util::ConvertBSTRToString((_bstr_t)var); if (i_Count>=20)
{
i_FileCount++;
i_Count=0;
}
m_FileName.Format("indexq[%d].html",i_FileCount);
ofstream fout(m_FileName,ios::app);
string str,str1;
str1=" <p><a href=\"/index.htm\">首页</a> / 新闻</p>";
if(i_Count==1)
{
while (getline (fin, str) )
{
fstream fout(m_FileName,ios::app);
if(fout)
{
fout<<str<<endl;
}
if(0==strcmp(str1.c_str(),str.c_str()) )
{
int m=1;
if(m)
{
ofstream fout(m_FileName,ios::app);
fout<<"<div>"<<endl;
fout<<"<h2>全部新闻</h2>"<<endl;
fout.close();
goto here;
}
}
}
here: fin.close();
}
fout<<strTitle<<"-"<<strClass<<" - "<<strNum<<" <br/>"<<endl;
fout.close();
m_pRecordset->MoveNext();
}
我是希望这个程序从数据库读数据,每20条数据库记录产生一个页面文件,
if(i_Count==1),把一个已有文件内容输入产生的页面文件。可调式的时候,
if(i_Count==1),下面的代码只执行一次不知道为什么?明明i_Count==1了,可他就是不执行下面的代码
请大家帮我看一看什么问题
不过你有个这个
if (i_Count>=20)
{
i_FileCount++;
i_Count=0;
}
像LS说的debug单步调试看看吧
我的代码:
while(!m_pRecordset->adoEOF)
{
i_Count++;
n++;
var = m_pRecordset->GetCollect("title");
if(var.vt != VT_NULL)
strTitle = _com_util::ConvertBSTRToString((_bstr_t)var); var = m_pRecordset->GetCollect("class");
if(var.vt != VT_NULL)
strClass = _com_util::ConvertBSTRToString((_bstr_t)var); var = m_pRecordset->GetCollect("num");
if(var.vt != VT_NULL)
strNum = _com_util::ConvertBSTRToString((_bstr_t)var); if (i_Count>=20)
{
i_FileCount++;
i_Count=0;
m_FileName.Format("indexq[%d].html",i_FileCount);
DeleteFile(m_FileName);
}
m_FileName.Format("indexq[%d].html",i_FileCount);
ofstream fout(m_FileName,ios::app);
string str,str1;
str1=" <p><a href=\"/index.htm\">首页</a> / 新闻</p>";
if(0==i_Count)
{
ifstream fin("index.html");
while (getline (fin, str) )
{
ofstream fout(m_FileName,ios::app);
if(fout)
{
fout<<str<<endl;
}
if(0==strcmp(str1.c_str(),str.c_str()) )
{
int m=1;
if(m)
{
ofstream fout(m_FileName,ios::app);
fout<<"<div>"<<endl;
fout<<"<h2>全部新闻</h2>"<<endl;
fout.close();
fin.close();
goto here;
}
}
}
}
here: ;
fout<<strTitle<<"-"<<strClass<<" - "<<strNum<<" <br/>"<<endl;
fout.close();
m_pRecordset->MoveNext();
}
那我现在想在每个文件的数据库的20条记录写完后,再从一个已有文件里向每个文件添加相同的内容,应该怎么写?大家帮我想想
file1.Open(m_Path1,CFile::modeRead);
out.Open("tmp.tmp",CFile::modeCreate|CFile::modeWrite);
CString strTemp;
while (file1.ReadString(strTemp))
{
if (strTemp == ""/*应该插入时的匹配字符串*/)
{
file1.Open(m_Path2,CFile::modeRead);
CString strTemp2;
strTemp="";
while (file2.ReadString(strTemp2))
{
strTemp+=strTemp2+_T("\n");
}
file2.Close();
}
out.WriteString(strTemp);
}
file1.Close();
DeleteFile(m_Path1);
out.Close();
out.Rename("tmp.tmp",m_Path1);
void CHtmlDlg::OnAll()
{
_variant_t var;
int i_Count=-1;
CString m_FileName;
ifstream fin("index.html");
char * strClass,* strNum,* strTitle;
try
{
if(!m_pRecordset->BOF)
m_pRecordset->MoveFirst();
else
{
AfxMessageBox("表内数据为空");
return;
}
m_pRecordset->MoveFirst();
int i_Count=-1;
int i_FileCount=0;
DeleteFile("indexq[0].html"); while(!m_pRecordset->adoEOF)
{
i_Count++;
var = m_pRecordset->GetCollect("title");
if(var.vt != VT_NULL)
strTitle = _com_util::ConvertBSTRToString((_bstr_t)var); var = m_pRecordset->GetCollect("class");
if(var.vt != VT_NULL)
strClass = _com_util::ConvertBSTRToString((_bstr_t)var); var = m_pRecordset->GetCollect("num");
if(var.vt != VT_NULL)
strNum = _com_util::ConvertBSTRToString((_bstr_t)var); if (i_Count>=20)
{
i_FileCount++;
i_Count=0;
m_FileName.Format("indexq[%d].html",i_FileCount);
DeleteFile(m_FileName);
}
m_FileName.Format("indexq[%d].html",i_FileCount);
ofstream fout(m_FileName,ios::app);
string str,str1;
str1=" <p><a href=\"/index.htm\">首页</a> / 新闻</p>";
if(0==i_Count)
{
ifstream fin("index.html");
while (getline (fin, str) )
{
ofstream fout(m_FileName,ios::app);
if(fout)
{
fout<<str<<endl;
}
if(0==strcmp(str1.c_str(),str.c_str()) )
{
int m=1;
if(m)
{
ofstream fout(m_FileName,ios::app);
fout<<"<div>"<<endl;
fout<<"<h2>全部新闻</h2>"<<endl;
fout<<" <h5>共有"<<m_pRecordset->GetRecordCount()<<"条新闻"<<endl;
fout<<" 第"<<i_FileCount+1<<"页"<<endl;
int n,m,i=1;
n=(m_pRecordset->GetRecordCount())/20;
m=(m_pRecordset->GetRecordCount())%20;
if(m!=0)
{
n=n+1;
}
while(n)
{
n--;
fout<<i<<endl;
i++;
}
fout<<" </h2>"<<endl;
fout.close();
fin.close();
goto here;
}
}
}
}
here: ;
fout<<strTitle<<"-"<<strClass<<" - "<<strNum<<" <br/>"<<endl;
fout.close();
m_pRecordset->MoveNext();
}
m_pRecordset->MoveFirst();
i_Count=-1;
while(!m_pRecordset->adoEOF)
{
i_Count++;
if (i_Count>=20)
{
i_FileCount++;
i_Count=0;
}
m_FileName.Format("indexq[%d].html",i_FileCount);
ofstream fout(m_FileName,ios::app);
ifstream fin("index.html");
if(0==i_Count)
{
fout<<"</div>"<<endl;
string str1,str2;
str2="<div id=\"table_top_GD_r\" class=\"full-captop_r\" style=\"height:620px\">";
while(1)
{
getline(fin,str1);
if(0==strcmp(str1.c_str(),str2.c_str()))
break;
}
while (getline (fin, str1) )
{
ofstream fout(m_FileName,ios::app);
if(fout)
{
fout<<str1<<endl;
fout.close();
}
}
fout.close();
fin.close();
}
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
}