这个(小)功能是便携的吗? [英] Is this (tiny) function portable?

查看:97
本文介绍了这个(小)功能是便携的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我缺少std :: string的某些功能,所以我目前正在编写一些对字符串进行操作的辅助函数。在它们上面是

跟随(它实际上是两个函数):


内联字符to_lower(char c)

{

if(c> = 65& c< = 90)// AZ

返回c + = 32;

返回c;

}


inline void str_to_lower(std :: string& source)

{

std :: transform(source.begin(),source.end(),source.begin(),

to_lower);

}


我的问题涉及到to_lower的功能:

这可移植吗?我查看了一个ASCII表,并认识到我可以通过添加32来将大写字母转换为小写字母。但是,如果这对其他字符有效,我没有

的想法桌子。


-

问候,

马蒂亚斯

Hello,

I am missing certain functionality of std::string, so I am currently
writing some helper functions which operate on strings. On of them is as
follows (it''s actually two functions):

inline char to_lower ( char c )
{
if( c>=65 && c<=90 ) // A-Z
return c += 32;
return c;
}

inline void str_to_lower ( std::string& source )
{
std::transform( source.begin(), source.end(), source.begin(),
to_lower );
}

My question concerns the function to_lower:
Is this portable? I looked at an ASCII table, and recognized that I can
convert uppercase letters to lowercase by adding 32. However, I have no
idea if this will work for other character tables.

--
Regards,
Matthias

推荐答案

* Matthias:
* Matthias:
你好,

我缺少std :: string的某些功能,所以我目前正在编写一些辅助函数对字符串进行操作。在它们之上是
跟随它(它实际上是两个函数):

内联char to_lower(char c)
{
if(c> = 65) && c< = 90)// AZ
返回c + = 32;
返回c;
}
内联void str_to_lower(std :: string& ;来源)
{st / :: transform(source.begin(),source.end(),source.begin(),
to_lower);
}

我的问题涉及to_lower的功能:
这是便携式吗?我查看了一个ASCII表,并认识到我可以通过添加32将大写字母转换为小写。但是,如果这对其他字符表有效,我没有想法。
Hello,

I am missing certain functionality of std::string, so I am currently
writing some helper functions which operate on strings. On of them is as
follows (it''s actually two functions):

inline char to_lower ( char c )
{
if( c>=65 && c<=90 ) // A-Z
return c += 32;
return c;
}

inline void str_to_lower ( std::string& source )
{
std::transform( source.begin(), source.end(), source.begin(),
to_lower );
}

My question concerns the function to_lower:
Is this portable? I looked at an ASCII table, and recognized that I can
convert uppercase letters to lowercase by adding 32. However, I have no
idea if this will work for other character tables.




它不便携。


查看''tolower''功能。


注意参数和结果类型。


-

答:因为它弄乱了人们通常阅读文本的顺序。

问:为什么这么糟糕?

A:热门发布。

问:usenet和电子邮件中最烦人的事情是什么?



It''s not portable.

Check out the ''tolower'' function.

Beware of argument and result types.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


Alf P. Steinbach写道:
Alf P. Steinbach wrote:

查看''tolower''功能。


啊,本来可以猜到有类似的东西...... :)

我有一个问题。我包括< cctype>而不是< ctype.h>。

现在,我认为所有这些转发标头包含了

命名空间std中的C函数?但是,当我调用std :: tolower时,我收到一个错误

这个函数不存在。在没有命名空间前缀

的情况下调用时,它可以正常工作。为什么会这样?

小心参数和结果类型。

Check out the ''tolower'' function.
Ah, could have guessed that there is something like it... :)
I have a question though. I included <cctype> instead of <ctype.h>.
Now, I thought all those forwarding headers wrap the C-functions in the
namespace std? However, when I call std::tolower, I get an error that
this function doesn''t exist. When calling without the namespace-prefix
it works just fine. Why ist that?

Beware of argument and result types.



你的意思是什么?


-

问候,

Matthias


What do you mean?

--
Regards,
Matthias


Matthias写道:
Matthias wrote:
你好,

我缺少std :: string的某些功能,所以我目前正在编写一些对字符串进行操作的辅助函数。在它们之上是
跟随它(它实际上是两个函数):

内联char to_lower(char c)
{
if(c> = 65) && c< = 90)// AZ
返回c + = 32;
返回c;
}
内联void str_to_lower(std :: string& ;来源)
{st / :: transform(source.begin(),source.end(),source.begin(),
to_lower);
}

我的问题涉及to_lower的功能:
这是便携式吗?


No.

我查看了一个ASCII表,并认识到我可以通过添加32将大写的
字母转换为小写。但是,我不知道这是否适用于其他角色表。
Hello,

I am missing certain functionality of std::string, so I am currently
writing some helper functions which operate on strings. On of them is as
follows (it''s actually two functions):

inline char to_lower ( char c )
{
if( c>=65 && c<=90 ) // A-Z
return c += 32;
return c;
}

inline void str_to_lower ( std::string& source )
{
std::transform( source.begin(), source.end(), source.begin(),
to_lower );
}

My question concerns the function to_lower:
Is this portable?
No.
I looked at an ASCII table, and recognized that I can convert uppercase
letters to lowercase by adding 32. However, I have no idea if this will
work for other character tables.




它不会。正如其他人提到的那样,只需使用tolower()。



It won''t. As someone else mentioned, just use tolower().


这篇关于这个(小)功能是便携的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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