CString转换成const char*的问题
CStringstrAviFilePath="D:/car.avi";//定义如下一个函数constchar*filename=strAviFilePath;//这条语句...
CString strAviFilePath="D:/car.avi";
//定义如下一个函数
const char* filename =strAviFilePath;//这条语句如何正确赋值
即是:如何将CString转换成const char*,strAviFilePath的值如何赋给filename,希望求助于高手,最好写明如何赋值的语句,在线等待中,不胜感激!
我用的编程环境是vc2005 展开
//定义如下一个函数
const char* filename =strAviFilePath;//这条语句如何正确赋值
即是:如何将CString转换成const char*,strAviFilePath的值如何赋给filename,希望求助于高手,最好写明如何赋值的语句,在线等待中,不胜感激!
我用的编程环境是vc2005 展开
2个回答
展开全部
CString类里面有一个成员函数
CString::GetBuffer
LPTSTR GetBuffer( int nMinBufLength );
throw( CMemoryException );
Return Value
An LPTSTR pointer to the object’s (null-terminated) character buffer.
Parameters
nMinBufLength
The minimum size of the character buffer in characters. This value does not include space for a null terminator.
于是乎 就可以这样
const char* filename =strAviFilePath.GetBuffer(sizeof(strAviFilePath));
CString::GetBuffer
LPTSTR GetBuffer( int nMinBufLength );
throw( CMemoryException );
Return Value
An LPTSTR pointer to the object’s (null-terminated) character buffer.
Parameters
nMinBufLength
The minimum size of the character buffer in characters. This value does not include space for a null terminator.
于是乎 就可以这样
const char* filename =strAviFilePath.GetBuffer(sizeof(strAviFilePath));
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询