std :: wcout和const char * [英] std::wcout and const char *
问题描述
嗨!
在将应用程序从ansi转换为unicode时,这是一个问题,即std :: wcout接受一个const char *而没有抱怨编译时间。
这个编译并运行:
---------------------- --------
const char * lookup()
{
returnHello world;
}
std :: wcout<< lookup();
------------------------------
我希望编译时间失败,所以我可以正确地将这样的情况转换成像这样的unicode。
任何想法?
问候,
Erik Knudsen
Hi!
In converting applications from ansi to unicode, it is a problem that
the std::wcout accepts a const char * without complaining compile time.
This compiles and runs:
------------------------------
const char *lookup()
{
return "Hello world";
}
std::wcout << lookup();
------------------------------
I would like it to fail compile time, so I can properly convert cases
like this to unicode in a meaningful way.
Any ideas?
Regards,
Erik Knudsen
推荐答案
2007年11月12日10: 16 AM,Erik Knudsen写道:
On 12/11/2007 10:16 AM, Erik Knudsen wrote:
嗨!
在将应用程序从ansi转换为unicode时,问题是
std :: wcout接受一个const char *而没有抱怨编译时间。
这个编译并运行:
- ----------------------------
const char * lookup()
{
返回Hello world;
}
std :: wcout<< lookup();
------------------------------
我希望编译时间失败,所以我可以正确地将这样的情况转换成像这样的unicode。
任何想法?
Hi!
In converting applications from ansi to unicode, it is a problem that
the std::wcout accepts a const char * without complaining compile time.
This compiles and runs:
------------------------------
const char *lookup()
{
return "Hello world";
}
std::wcout << lookup();
------------------------------
I would like it to fail compile time, so I can properly convert cases
like this to unicode in a meaningful way.
Any ideas?
声明并且不自己定义std :: operator<<(wostream&,char const *)?
命名空间std
{
inline
wostream& operator<<(wostream& wos,const char *);
}
只是一个想法...
S.
-
Stefan Naewe stefan dot naewe at atlas-elektronik dot com
不要顶尖 http://www.catb.org/~esr/jargon/html/T /top-post.html
仅限纯文本邮件,请 http://www.expita.com/nomime.html
Stefan Naewe写道:
Stefan Naewe wrote:
>我希望编译时间失败,所以我可以正确地将这样的案例转换为unicode。
任何想法?
>I would like it to fail compile time, so I can properly convert cases
like this to unicode in a meaningful way.
Any ideas?
声明并且不自己定义std :: operator<<(wostream&,char const *)?
命名空间std
{
inline
wostream& operator<<(wostream& wos,const char *);
}
只是一个想法...
Declare and do not define std::operator<<(wostream&, char const*) yourself?
namespace std
{
inline
wostream& operator<<(wostream& wos, const char*);
}
Just an idea...
谢谢,但是这不会给我一个链接器错误,没有参考
到代码行吗?
问候,
Erik Knudsen
Thanks, but wouldn''t that just give me a linker error, with no reference
to code lines?
Regards,
Erik Knudsen
在12/12/2007 10:01 AM,Erik Knudsen写道:
On 12/12/2007 10:01 AM, Erik Knudsen wrote:
Stefan Naewe写道:
Stefan Naewe wrote:
>>我希望编译时失败,所以我可以正确转换案例
这样以有意义的方式进行unicode。
任何想法?
>>I would like it to fail compile time, so I can properly convert cases
like this to unicode in a meaningful way.
Any ideas?
声明并且不定义std :: operator<<(wostream&,char const *)
自己?
namespace std
{
内联
wostream& operator<<(wostream& wos,const char *);
}
只是一个想法...
Declare and do not define std::operator<<(wostream&, char const*)
yourself?
namespace std
{
inline
wostream& operator<<(wostream& wos, const char*);
}
Just an idea...
谢谢,但是这不会给我一个链接器错误,没有参考
代码行?
Thanks, but wouldn''t that just give me a linker error, with no reference
to code lines?
是......但是:
如果我调用''g ++ -g'',链接器会给我文件和行号:
g ++ -g -Wall wchar.cc -o wchar
/tmp/ccLf8VPM.o:在函数`main''中:
wchar.cc:37:未定义引用`std :: operator<<(std :: basic_ostream< wchar_t,std :: char_traits< wchar_t&,char const *)''
collect2:ld返回1退出状态
make:*** [wchar] Fehler 1
HTH
S.
-
Stefan Naewe stefan dot naewe at atlas-elektronik dot com
不要顶一下 http://www.catb.org/~esr/jargon/html/ T / top-post.html
纯文本邮件,请 http://www.expita.com/nomime.html
这篇关于std :: wcout和const char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!