字母大小写转换可以不用循环吗

本文详细介绍了在不使用循环的情况下实现字母大小写转换的多种方法,并提供了具体的代码示例,包括使用标准库函数如transform和toupper等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

字母大小写转换可以不用循环吗
2011年03月22日
  2011-03-22 wcdj 问题描述:
  i wanna to make a prog which convert small case letters entered by user to upper case letters....i TRIED to use toupper function ...but it only do action with a single character...is there any function which convert all characters like "lovely hakeem" to "LOVELY HAKEEM"
  (NOT BY LOOP)
  There is no way to convert all characters to upper or lower case without looping through the string.
  下面总结几种常用的大写转小写的方法
  方法1:逐个字符判断,是大写字母+32
  #include #include int main() { char str[128]; gets(str); for (int i = 0; i = 'A' && str[i] #include #include using namespace std; int main() { string str; cin>>str; transform(str.begin(),str.end(),str.begin(),tolowe r); cout #include #include char msg[] = "Some of THESE letters are Capitals\r\n"; char *p; void main( void ) { _cputs( msg ); /* Reverse case of message. */ for( p = msg; p #include int main( void ) { char string[100] = "The String to End All Strings!"; printf( "Mixed: %s\n", string ); _strlwr(string);// C库函数变小写 printf( "Lower: %s\n", string); _strupr(string);// C库函数变大写 printf( "Upper: %s\n", string); } PS: A foreigner's method // You can do your own easily enough: // C #include char* stoupper( char* s ) { char* p = s; while (*p = toupper( *p )) p++; return s; } // C++ #include #include #include std::string& stoupper( const std::string& s ) { std::string result( s ); std::transform( s.begin(), s.end(), result.begin(), std::ptr_fun ( std::toupper ) ); return result; } //Etc. Hope this helps. 更多内容参考:
  http://www.cplusplus.com/forum/general/33439/
  http://www.cplusplus.com/forum/beginner/14081/
  http://topic.youkuaiyun.com/u/20071015/21/4c266542-c3a6- 4a5a-9754-fc7574ca5ef6.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值