简体   繁体   English

如何将CString转换为字节

[英]how to convert CString to Bytes

i am actually tryin to convert a csharp code to c... below is the C# code.. 我实际上是在尝试将csharp代码转换为c ...下面是C#代码..

CString data = "world is beautiful";    
Byte[] quote = ASCIIEncoding.UTF8.GetBytes(data);

in the above code... it converts the string into bytes..similarily is ther a way that i can convert it using C.. Can any body tell what wud be the quivalent code in C? 在上面的代码中...它将字符串转换成字节。.同样是我可以使用C转换它的一种方法。任何机构都可以说出C中的等效代码是什么吗? Please help me guys 请帮我

Well CString is a C++ class so doing it in C is a little unlikely. 好吧,CString是C ++类,因此在C中执行它的可能性很小。

But if you wish to get it as a standard multi-byte encoded string then you can do the following 但是,如果您希望将其作为标准的多字节编码字符串来获取,则可以执行以下操作

CString data    = "world is beautiful";
CStringA mbStr  = data;
char* bytes     = mbStr.GetString();

In C the char type is defined as one byte in memory. 在C语言中,char类型定义为内存中的一个字节。 Hence storing your string as a char * would be equivalent to storing a byte array in C#. 因此,将您的字符串存储为char *等同于将字节数组存储在C#中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM