时代倾城4期:哪位大爷能教下我C++的基础问题啊!?

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/04 18:39:57
#include <iostream>
using namespace std;
void main()
{
int number;
char character;

cout << "Type in a character:\n";
cin >> character;

number = character;

cout << "The character '" << character;
cout << "' is represented as the number ";
cout << number << " in the computer.\n";
}

要求输入一个整数类型的十进制数(000-255),接着把该整数以字符形式输出。
运行结果为:
请输入一个0-255之间的整数:97
你刚输入的数 ‘97’ 转换成字符是:a
我用的是VC.NET

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
char c[3];
printf("enter a number");
scanf("%s",&c);
char a = atoi(c);
printf("%c",a);

system("pause");
return 0;
}

//atoi--->把字符串转换成整型
字符串“97”转换成整型的97

。。。强制类型转换阿

Aztack - 魔法师 四级
回答的太好了.