求教a变A

pigniyan 2008-11-03 03:04:01
在C++中如何输入一个小a让它变成大A?
...全文
179 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
SYSDP 2008-11-03
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 Donald_Duck 的回复:]
7楼的的位运算方法很好,但应该是和第6位做与运算吧,即a&0xCF
[/Quote]

10,0000=2^5=32
9楼的哥们,好细心啊,赞一个,可以嘛
jia_xiaoxin 2008-11-03
  • 打赏
  • 举报
回复
	char ch;
cin >> ch;
ch += 'A' - 'a';
cout << ch ;
yjyq1990 2008-11-03
  • 打赏
  • 举报
回复
char temp;
temp=a;
temp-=32;
cout<<temp<<endl;
楼上太麻烦了一点。不用引用string,而且str不用初始化。
tengye19840704 2008-11-03
  • 打赏
  • 举报
回复
// CSDNTEST081031.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
char str = 'a' ;
cin>>str;
str = str - 32;
cout<<str<<endl;
return 0;
}


nullah 2008-11-03
  • 打赏
  • 举报
回复

#include <iostream>
#include <cctype>
using namespace std;

int main()
{
char a = 'a';
cout << (char)toupper(a) << endl;
cout << (char)(a-32) << endl;

return 0;
}

Donald_Duck 2008-11-03
  • 打赏
  • 举报
回复
7楼的的位运算方法很好,但应该是和第6位做与运算吧,即a&0xCF
e_sharp 2008-11-03
  • 打赏
  • 举报
回复
toupper

#include <ctype.h>
feng4206yu 2008-11-03
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;

int main()
{
char a = 'a';
char b =(a & 0xDF);
cout<<b<<endl;

return 0;
}

ASCII小写英文字母的编码比对应大写字母编码要大32,具体表现在小写字母编码二进制的第五位是1,而对应大写字母编码二进制的第五位为0,其余位相同,所以用位运算比较方便...
yh4130a 2008-11-03
  • 打赏
  • 举报
回复
ASCII码 自己加减就OK
insulted 2008-11-03
  • 打赏
  • 举报
回复
(1):用系统函数 toupper()
(2): 'A'='a'-32
vk2211 2008-11-03
  • 打赏
  • 举报
回复
'A'='a'-32
Longinc 2008-11-03
  • 打赏
  • 举报
回复
用系统函数 toupper
insuya 2008-11-03
  • 打赏
  • 举报
回复
#include <ctype.h>

char c1 = 'a';
char c2 = toupper(cch);
wuyu637 2008-11-03
  • 打赏
  • 举报
回复
oupper


原型:extern int toupper(int c);

用法:#include <ctype.h>

功能:将字符c转换为大写英文字母

说明:如果c为小写英文字母,则返回对应的大写字母;否则返回原来的值。

举例:


// toupper.c

#include <syslib.h>
#include <ctype.h>

main()
{
char *s="Hello, World!";
int i;

clrscr(); // clear screen
printf("%s\n",s);
for(i=0;i<strlen(s);i++)
{
putchar(toupper(s[i]));
}

getchar();
return 0;
}

64,636

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧