CString不会去cout [英] CString will not go to cout

查看:89
本文介绍了CString不会去cout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

展开 | 选择 | Wrap | 行号

推荐答案

因为printf(和类似函数)中的%s表示堆栈上的参数指向到ac字符串,这是一个零终止的字符数组。您的变量st是CString类型的对象,而不是指向c字符串的指针。但是你可以将它转换成一个指向交流字符串的常量指针


(LPCSTR)st / /

因为CString对象为此实现了一个运算符所以


printf_s("%s \ n",(LPCSTR)st);


应该适合你。
Because %s in printf (and similar functions) indicates a parameter on the stack that points to a c string, that is a zero terminated array of characters. Your variable, st is an object of type CString not a pointer to a c string. You can however cast it to a constant pointer to a c string

(LPCSTR)st

because the CString object implements an operator for this so

printf_s("%s\n",(LPCSTR)st);

should work for you.


展开 | 选择 | Wrap | 行号


对不起,另一件事是CString处理Windows正在使用的字符类型。这通常是unicode。


printf(及相关函数)但是仍然使用直的ASCII字符串。


要打印一个CString,你需要将字符从Unicode转换为ASCII。


应该通过google或msdn提供大量有关此内容的信息。
Sorry the other thing is that CString deals with what ever character type Windows is using. This is normally unicode.

printf (and related functions) however still use a straight ASCII string.

To printf a CString you will need to convert the characters from Unicode to ASCII.

There should be plenty of information about this available either through google or msdn.


这篇关于CString不会去cout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆