CString转换为const char [英] CString to const char conversion
问题描述
我收到以下错误:
''strlen'':无法将参数1从''class CString''转换为''const char *''<当我尝试编译以下代码时,
:
HRESULT AnsiToUnicode(CString pszA,LPOLESTR * ppszW)
{
ULONG cCharacters;
DWORD dwError;
//如果输入为null,则返回相同的内容。
if(NULL == pszA)
{
* ppszW = NULL;
返回NOERROR;
}
//确定要为
// Unicode字符串分配的宽字符数。
cCharacters = strlen(pszA)+1; < -------------------------
............... ...........
}
有关问题的建议吗?
Fausto
I''m getting the following error:
''strlen'' : cannot convert parameter 1 from ''class CString'' to ''const char *''
when I try to compile the following code:
HRESULT AnsiToUnicode(CString pszA, LPOLESTR* ppszW)
{
ULONG cCharacters;
DWORD dwError;
// If input is null then just return the same.
if (NULL == pszA)
{
*ppszW = NULL;
return NOERROR;
}
// Determine number of wide characters to be allocated for the
// Unicode string.
cCharacters = strlen(pszA)+1; <-------------------------
..........................
}
Any suggestions as to what the problem might be?
Fausto
推荐答案
Fausto Lopez写道:
Fausto Lopez wrote:
我收到以下错误:
''strlen'':当我尝试编译以下代码时,无法将参数1从''class CString''转换为''const char *'
:
HRESULT AnsiToUnicode(CString pszA,LPOLESTR * ppszW)
{
ULONG cCharacters;
DWORD dwError;
//如果输入为null,则返回相同的内容。
if(NULL == pszA)
{
* ppszW = NULL;
返回NOERROR;
}
//确定宽字符的数量分配给
// Unicode字符串。
cCharacters = strlen(pszA)+1; < -------------------------
................... ......
有关问题的建议吗?
Fausto
I''m getting the following error:
''strlen'' : cannot convert parameter 1 from ''class CString'' to ''const char *''
when I try to compile the following code:
HRESULT AnsiToUnicode(CString pszA, LPOLESTR* ppszW)
{
ULONG cCharacters;
DWORD dwError;
// If input is null then just return the same.
if (NULL == pszA)
{
*ppszW = NULL;
return NOERROR;
}
// Determine number of wide characters to be allocated for the
// Unicode string.
cCharacters = strlen(pszA)+1; <-------------------------
.........................
}
Any suggestions as to what the problem might be?
Fausto
CString不是C ++语言的一部分。
许多字符串类都有一种方法可以从C-Style字符串转换为
。如果你使用的是std :: string
类,你可以使用std :: sting :: c_str()方法。
查看CString类是否有类似的方法。
-
托马斯马修斯
C ++新闻组欢迎辞:
http://www.slack.net/~shiva/welcome.txt
C ++常见问题: http://www.parashift .com / c ++ - faq-lite
C常见问题: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn。 c-c ++ faq:
http:// www .raos.demon.uk / acllc -c ++ / faq.html
其他网站:
http://www.josuttis.com - C ++ STL Library bo好的
CString is not a part of the C++ language.
Many string classes have a method to convert to and
from C-Style strings. If you were using the std::string
class, you would use the std::sting::c_str() method.
See if the CString class has a similar method.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
Fausto Lopez写道:
Fausto Lopez wrote:
我收到以下错误:
' 'strlen'':当我尝试编译以下代码时,无法将参数1从''class CString''转换为''const char *''
HRESULT AnsiToUnicode(CString pszA,LPOLESTR * ppszW)
{
ULONG cCharacters;
DWORD dwError;
//如果输入为null,则返回相同的内容。
if(/ NULL == pszA)
{
* ppszW = NULL;
返回NOERROR;
}
//确定要为
// Unicode字符串。
cCharacters = strlen(pszA)+1; < -------------------------
................... ......
有关问题的建议吗?
I''m getting the following error:
''strlen'' : cannot convert parameter 1 from ''class CString'' to ''const char *''
when I try to compile the following code:
HRESULT AnsiToUnicode(CString pszA, LPOLESTR* ppszW)
{
ULONG cCharacters;
DWORD dwError;
// If input is null then just return the same.
if (NULL == pszA)
{
*ppszW = NULL;
return NOERROR;
}
// Determine number of wide characters to be allocated for the
// Unicode string.
cCharacters = strlen(pszA)+1; <-------------------------
.........................
}
Any suggestions as to what the problem might be?
不。 CString(IIRC)定义了''const const char *'',因此它应该被转换为
。
不幸的是,更多细节因为
所以MFC类都不是标准C ++的一部分。试试新闻组
microsoft.public.vc.mfc或comp.os.ms-windows.programmer.tools.mfc
Victor
Nope. CString (IIRC) has ''operator const char*'' defined, so it
should be picked up for the conversion.
Unfortunately, any more detail on this is off-topic here since
none of MFC classes are part of standard C++. Try the newsgroup
microsoft.public.vc.mfc or comp.os.ms-windows.programmer.tools.mfc
Victor
Fausto Lopez写道:
Fausto Lopez wrote:
我收到以下错误:
''strlen'':不能将参数1从''class CString''转换为''const char
*''
尝试 http://groups.google.com 找到一个有资格讨论CString的小组。
这个小组只能可靠地讨论平台中立的C ++ 。
当我尝试编译以下代码时:
HRESULT AnsiToUnicode(CString pszA,LPOLESTR * ppszW)
{
Oookay。没有人再使用匈牙利表示法了。但是psz表示指向
零终止字符串的指针。这个冗余部门使用非类型安全约定在
C工作。 CString是一个对象。
ULONG cCharacters;
DWORD dwError;
//如果输入为null,则返回相同的内容。
if(NULL == pszA)
此代码将pszA视为指针,而不是对象。试试pszA.IsEmpty()。
{
* ppszW = NULL;
返回NOERROR;
}
//确定宽字符的数量分配给
// Unicode字符串。
cCharacters = strlen(pszA)+1; < -------------------------
I''m getting the following error:
''strlen'' : cannot convert parameter 1 from ''class CString'' to ''const char *''
Try http://groups.google.com to find a group qualified to discuss CString.
This group can only reliably discuss platform neutral C++.
when I try to compile the following code:
HRESULT AnsiToUnicode(CString pszA, LPOLESTR* ppszW)
{
Oookay. Nobody uses Hungarian Notation anymore. But "psz" means "pointer to
zero terminated string". This Department of Redundancy Department worked in
C using untypesafe conventions. CString is an object.
ULONG cCharacters;
DWORD dwError;
// If input is null then just return the same.
if (NULL == pszA)
This code treats pszA as a pointer, not an object. Try pszA.IsEmpty().
{
*ppszW = NULL;
return NOERROR;
}
// Determine number of wide characters to be allocated for the
// Unicode string.
cCharacters = strlen(pszA)+1; <-------------------------
pszA有什么问题.GetLength()?
我不知道pszA.operator LPCTSTR()有什么问题,但你不需要
$ b $它。你可以多学习一下C ++和MS库
提供CString。
另外,MFC糟透了,但你似乎没有使用所有这些。试试WTL。
-
Phlip
http://industrialxp.org/community/bi...UserInterfaces
这篇关于CString转换为const char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!