如何避免使用数组的字符串??? [英] How to avoid using arrays for strings???

查看:56
本文介绍了如何避免使用数组的字符串???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(我正在给comp.lang.c ++和comp.os.ms-

windows.programmer.win32

,因为那里有这里的Windows材料以及与

标准相关的问题

C ++。不确定如何在comp.lang.c ++中进行更新。如果其中一个

这些团体

太不合适了,只需从发送回复的地方取下。)


您好。


我正在用C ++编写Windows OS程序。但似乎

Windows

函数都接受类型为TCHAR的字符串_arrays_。 (实际上,

_pointers_到

数组),可以在C / C ++基元类型之间切换

wchar_t / char,
前者用于Unicode编码。请问C ++ STL



std :: string / std :: wstring在这种情况下有效吗?它是如何与

Unicode

编码冲突的,如果有的话?无论谁提出

标准我都会生气。

它有问题,因为UNICODE被各种现代使用了

操作

系统,而不仅仅是Windows!


但是对于C ++,据说阵列是邪恶的。是否可以使用

C ++ STL

函数用于所有内部字符串操作_甚至我想要

Unicode支持_

然后只有当我需要将它发送到Windows

函数时才转换为数组?

如果没有,我应该去预先使用数组,或者在至少写一下

一些定制的

容器会掩埋邪恶的东西。 TCHAR的数组,保持它们的价值

的方式

并打包?

(I''m xposting this to both comp.lang.c++ and comp.os.ms-
windows.programmer.win32
since there''s Windows material in here as well as questions related to
standard
C++. Not sure how that''d go over at just comp.lang.c++. If one of
these groups is
too inappropriate, just take it off from where you send your replies.)

Hi.

I''m writing a program for the Windows OS in C++. But it seems the
Windows
functions all accept string _arrays_ of type "TCHAR" (actually,
_pointers_ to
arrays), which can be toggled between the C/C++ primitive types
wchar_t/char,
the former of which is used for Unicode encoding. Will the C++ STL
classes
std::string/std::wstring work in this case? How does it clash with the
Unicode
encodings, if at all? I''d be mad with whoever comes up with the
standards if
it had a problem since UNICODE is used by all sorts of modern
operating
systems, not just Windows!

But with C++, it is said that arrays are "evil". Is it possible to use
the C++ STL
functions for all internal string manipulations _even while I want
Unicode support_
and then only convert to array when I need to send it to the Windows
functions?
If not, should I go and just use arrays up front, or at least write up
some custom
container that will bury the "evil" arrays of TCHAR, keeping them out
of the way
and packaged?

推荐答案

11月16日00:30,mike3< mike4 ... @ yahoo.comwrote:
On 16 Nov., 00:30, mike3 <mike4...@yahoo.comwrote:

(我正在向comp.lang发送此信息。 c ++和comp.os.ms-

windows.programmer.win32

因为这里有Windows资料以及与
$ b相关的问题$ b标准

C ++。不确定如何在comp.lang.c ++中进行。如果其中一个

这些组是

太不合适了,只需从发送回复的地方取下它。)


嗨。


我正在写一个程序适用于C ++中的Windows操作系统。但似乎

Windows

函数都接受类型为TCHAR的字符串_arrays_。 (实际上,

_pointers_到

数组),可以在C / C ++基元类型之间切换

wchar_t / char,
前者用于Unicode编码。请问C ++ STL



std :: string / std :: wstring在这种情况下有效吗?它是如何与

Unicode

编码冲突的,如果有的话?无论谁提出

标准我都会生气。

它有问题,因为UNICODE被各种现代使用了

操作

系统,而不仅仅是Windows!


但是对于C ++,据说阵列是邪恶的。是否可以使用

C ++ STL

函数用于所有内部字符串操作_甚至我想要

Unicode支持_

然后只有当我需要将它发送到Windows

函数时才转换为数组?

如果没有,我应该去预先使用数组,或者在至少写一下

一些定制的

容器会掩埋邪恶的东西。 TCHAR阵列,让他们出局

的方式

和打包?
(I''m xposting this to both comp.lang.c++ and comp.os.ms-
windows.programmer.win32
since there''s Windows material in here as well as questions related to
standard
C++. Not sure how that''d go over at just comp.lang.c++. If one of
these groups is
too inappropriate, just take it off from where you send your replies.)

Hi.

I''m writing a program for the Windows OS in C++. But it seems the
Windows
functions all accept string _arrays_ of type "TCHAR" (actually,
_pointers_ to
arrays), which can be toggled between the C/C++ primitive types
wchar_t/char,
the former of which is used for Unicode encoding. Will the C++ STL
classes
std::string/std::wstring work in this case? How does it clash with the
Unicode
encodings, if at all? I''d be mad with whoever comes up with the
standards if
it had a problem since UNICODE is used by all sorts of modern
operating
systems, not just Windows!

But with C++, it is said that arrays are "evil". Is it possible to use
the C++ STL
functions for all internal string manipulations _even while I want
Unicode support_
and then only convert to array when I need to send it to the Windows
functions?
If not, should I go and just use arrays up front, or at least write up
some custom
container that will bury the "evil" arrays of TCHAR, keeping them out
of the way
and packaged?



对于作为常量数据传递的所有TCHAR,您可以使用std :: string或

std :: vector。如果

调用函数正在修改指向的,你当前必须使用

std :: vector。

没有必要使用原始阵列。


/ Peter

For all TCHARs passed as constant data, you can use std::string or
std::vector. If the
called function is modifying whats pointed to, you must currently use
std::vector.
There is no need to use a raw array.

/Peter


[发表于comp.os.ms-windows.programmer.win32]


mike3说:


< snip>
[Posted in comp.os.ms-windows.programmer.win32]

mike3 said:

<snip>

>

但是对于C ++,据说数组是邪恶的。
>
But with C++, it is said that arrays are "evil".



不要相信你所读的全部内容。这不是邪恶的阵列。如果你不理解它们是如何工作的,那么什么是邪恶的?使用数组是



因为数组只是最简单的聚合数据结构

可以想象,理解它们如何工作没有什么困难。


如果你想使用数组(并知道如何),请使用数组。不要被

错位的狂热者推迟。


< snip>


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

Don''t believe all you read. It isn''t arrays that are evil. What is evil is
using arrays if you don''t understand how they work.

Since arrays are just about the simplest aggregate data structure
imaginable, there is little difficulty in understanding how they work.

If you want to use arrays (and know how), use arrays. Don''t be put off by
misplaced zealotry.

<snip>

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


11月15日晚上9:26,Richard Heathfield< r ... @ see.sig.invalidwrote:
On Nov 15, 9:26 pm, Richard Heathfield <r...@see.sig.invalidwrote:

[发表于comp.os.ms-windows.programmer.win32]


mike3说:


< snip>
[Posted in comp.os.ms-windows.programmer.win32]

mike3 said:

<snip>

但是对于C ++,据说数组是邪恶的。
But with C++, it is said that arrays are "evil".



不要相信你所读的全部内容。这不是邪恶的阵列。如果你不理解它们是如何工作的,那么什么是邪恶的?使用数组是



因为数组只是最简单的聚合数据结构

可以想象,理解它们如何工作没有什么困难。


如果你想使用数组(并知道如何),请使用数组。不要被

错位的狂热者推迟。


Don''t believe all you read. It isn''t arrays that are evil. What is evil is
using arrays if you don''t understand how they work.

Since arrays are just about the simplest aggregate data structure
imaginable, there is little difficulty in understanding how they work.

If you want to use arrays (and know how), use arrays. Don''t be put off by
misplaced zealotry.



然而,这些担忧并非仅仅基于声称

数组是邪恶的,但也在这篇帖子中给出了

讨论早期版本的程序时有
a bug它,我在其中一个回复中得到了这个:

http://groups.google.com/group/comp....6278b77597d648


我看到的主要设计问题,只是粗略地看一下代码,



a混合非常高级别(抽象操作)和低级别

(指针,

施放),一个抽象缺口,表示一个或多个缺失的中间水平。

尝试将低级别操作封装在某些非 - 非常高级

班。例如,这样的封装类或函数可以实现所有

指针的东西,从错误代码转换为异常等等。只需

获取那些导致错误的低级别东西/打包/打包。

Else-thread我已经提到了那个高的另一个方面
等级

低级冲突,使用std :: vector

而不是原始数组和指针的
是个好主意。


看,他说使用std :: vector而不是raw

数组/指针。

However, the concerns weren''t just based on the claims the
arrays are "evil", but also on this post that was given
when discussing an earlier version of the program which had
a bug in it, and I got this in one of the responses:

http://groups.google.com/group/comp....6278b77597d648

"The main design problem I saw, with just a cursory look at the code,
was
a mix of very high level (abstract operations) and low level
(pointers,
casting), an abstraction gap, indicating one or more missing
intermediate levels.
Try to encapsulate low-level operations in some not-very-high-level
classes. For example, such encapsulation classes, or functions, do
all
pointer stuff, translate from error codes to exceptions, etc. Just
getting that bug-inducing low level stuff /out of the way/, packaged.
Else-thread I have already mentioned another aspect of that high
level
low level clash, that it would be a good idea to use std::vector
instead
of raw arrays and pointers. "

See, he said about the use of std::vector instead of raw
arrays/pointers.


< snip>


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - 1999年7月29日dmr
<snip>

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


这篇关于如何避免使用数组的字符串???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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