以下是我的程序:
try
{
//读取模版程序
CFile m_fileOpen,m_fileWrite;
CFileException m_fileE;
if (m_fileOpen.Open(_T(".\\模版\\redline.txt"),CFile::modeRead))
{
char cRead;
DWORD dwByteOfFile = (DWORD)m_fileOpen.GetLength();
UINT nByteOfRead;
m_fileWrite.Open(_T(".\\转换结果\\mytry.htm"),CFile::modeCreate|CFile::modeWrite,&m_fileE);
while (dwByteOfFile)
{
nByteOfRead = m_fileOpen.Read(&cRead,sizeof(cRead));
dwByteOfFile -= nByteOfRead;
m_fileWrite.Write(&cRead,nByteOfRead);
}
m_fileOpen.Close();
}
if (m_fileOpen.Open(_T(strFilePath[0]),CFile::modeRead,&m_fileE))
{
char cRead;
DWORD dwByteOfFile=(DWORD)m_fileOpen.GetLength();
UINT nByteOfRead;
//BYTE buffer[0x1000]; while (dwByteOfFile)
{
nByteOfRead = m_fileOpen.Read(&cRead,sizeof(cRead));
dwByteOfFile -= nByteOfRead;
m_fileWrite.Write(&cRead,nByteOfRead);
}
m_fileOpen.Close();
m_fileWrite.Close();
}
else
{
m_fileE.ReportError();
}
//GetDlgItem(IDC_FILEPATH)->GetWindowText(NULL,1);
}
catch (CException* e)
{
e->ReportError();
}
程序介绍:该程序的目的是合并两个文本文件.
问题:当我不指定文件二时,文件一的相对路径能够正常被解析,成功读写文件一,但一旦加入文件二后,结果文件一的相对路径就出错了,无法解析,调试发现文件一的路径总是被指定到当前文件所在盘符下的"\模版\redline.txt",例如:e:\模版\redline.txt,请问问题到底出在哪里?
try
{
//读取模版程序
CFile m_fileOpen,m_fileWrite;
CFileException m_fileE;
if (m_fileOpen.Open(_T(".\\模版\\redline.txt"),CFile::modeRead))
{
char cRead;
DWORD dwByteOfFile = (DWORD)m_fileOpen.GetLength();
UINT nByteOfRead;
m_fileWrite.Open(_T(".\\转换结果\\mytry.htm"),CFile::modeCreate|CFile::modeWrite,&m_fileE);
while (dwByteOfFile)
{
nByteOfRead = m_fileOpen.Read(&cRead,sizeof(cRead));
dwByteOfFile -= nByteOfRead;
m_fileWrite.Write(&cRead,nByteOfRead);
}
m_fileOpen.Close();
}
if (m_fileOpen.Open(_T(strFilePath[0]),CFile::modeRead,&m_fileE))
{
char cRead;
DWORD dwByteOfFile=(DWORD)m_fileOpen.GetLength();
UINT nByteOfRead;
//BYTE buffer[0x1000]; while (dwByteOfFile)
{
nByteOfRead = m_fileOpen.Read(&cRead,sizeof(cRead));
dwByteOfFile -= nByteOfRead;
m_fileWrite.Write(&cRead,nByteOfRead);
}
m_fileOpen.Close();
m_fileWrite.Close();
}
else
{
m_fileE.ReportError();
}
//GetDlgItem(IDC_FILEPATH)->GetWindowText(NULL,1);
}
catch (CException* e)
{
e->ReportError();
}
程序介绍:该程序的目的是合并两个文本文件.
问题:当我不指定文件二时,文件一的相对路径能够正常被解析,成功读写文件一,但一旦加入文件二后,结果文件一的相对路径就出错了,无法解析,调试发现文件一的路径总是被指定到当前文件所在盘符下的"\模版\redline.txt",例如:e:\模版\redline.txt,请问问题到底出在哪里?
解决方案 »
- 急急急!各位谁开发过OPC方面的程序啊
- 使用vc++6.0和使用VS2008开发C++程序有哪些区别?
- 大家看看这个用windbg进行的调试是不是只能在双机下进行?
- DWORD类型IP地址问题.
- 在对话框窗口指定RECT里创建窗口
- 我做了一个DLL,注入其他进程.在DLL中,我如何得到DLL在硬盘上的路径
- 用GlobalAlloc就发生例外发生的时候,用HeapAlloc就可以成功分配一块内存..是不是堆占溢出
- rc文件中有关宏定义问题,高手请,急!
- cstring 字符串截取问题
- VC 动态创建的CTreeCtrl,总被下面的CListCtrl遮挡,这个该怎么解决
- 如何实现多线程(或者异步)查询Sqlserver库?
- 我打开一个网页后,然后触发axWebBrowser3_DocumentComplete事件,为何有时候该函数会调用2次?
d:\vc\test\debug\a.txt程序的路径可以用__argv[ 0 ]来取得。
CString
GetMyPath( void )
{
CString s;
char tt[ 512 ] = "";
int i = strlen( __argv[ 0 ] );
memcpy( tt, __argv[ 0 ], i ); while( tt[ i ] != '\\' )
{
i--;
} s = ( CString )( tt + i + 1 );
return s;
}
bool GetAppPath(CString &path)//不包括最后的'\\'
{
CString sPath;
GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
sPath.ReleaseBuffer();
int i=sPath.GetLength()-1;
while(i>0)
{
if(sPath.GetAt(i)=='/' || sPath.GetAt(i)=='\\') break;
i--;
}
if(i<0) return false;
if(i==0) path=".";
else path=sPath.Left(i);
return true;
}