使用std :: string和std :: wstring实现CString [英] Implementing CString with std::string and std::wstring

查看:179
本文介绍了使用std :: string和std :: wstring实现CString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用std :: string和std :: wstring实现CString。

class CString

{

public:

std :: string str;

CString(){str =" ABCD";} //这个有效

}:


class CString

{

public:

std :: wstring wstr;

CString(){wstr =" ABCD" ;;} // this doesn''工作原理

}:

wstring为=运算符提供错误。我需要在这里为wstring添加什么?

我正在使用MS visual studio 2005,但我想让它独立于编译器。

解决方案

< blockquote>它给出了什么错误?


您是否尝试过L" ABCD"


您的Visual Studio项目具有charactert设置属性。这是您指定char或Unicode的位置。在您的代码中,永远不应该使用显式char或宽字符语法。


您编写代码以使用char和Unicode之间的Microsoft特定的amppings。对TCHAR映射进行重新研究。


请注意,Windoes使用Unicode进行所有处理。除非你的程序特别需要char字符集,否则你的程序中不应该使用char。


我想编写一个可以独立于OS的CString。宽炭可以实现吗?我正在尝试UNICODE。


Hi, I was trying to implement CString with std::string and std::wstring.
class CString
{
public:
std::string str;
CString() {str = "ABCD";} //this works
}:

class CString
{
public:
std::wstring wstr;
CString() {wstr = "ABCD";} //this doesn''t works
}:
The wstring is giving error for =operator. What do I need to add here for wstring?
I am using MS visual studio 2005, but I want to make it compiler independent.

解决方案

What error is it giving?

Have you tried L"ABCD"?


Your Visual Studio project has a charactert set property. This is where you specify char or Unicode. In your code there should never be explicit char or wide char syntax.

You write your code to use the Microsoft-specific amppings between char and Unicode. Do reasearch on the TCHAR mappings.

Note that Windoes does all processing using Unicode. Unless your program specifically needs the char character set, there should be no use of char in your program.


I want to write a CString which can be OS independent. Is this possible with wide char? I am trying for UNICODE only.


这篇关于使用std :: string和std :: wstring实现CString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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