用getchar函数读入两个字符给c1,c2,然后用putchar函数输出这两个字符。
#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char c1,c1;
c1 = getchar();
fflush(stdin);
c2 = getchar();
putchar(c1);
putchar(c2);
return 0;
}
如果要输出这两个字符的ASCII码,应如何处理?
#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int c1,c2;
c1 = getchar();
fflush(stdin);
c2 = getcha

本文介绍了如何在C++中利用getchar()函数读取字符,fflush(stdin)清除输入缓冲区,以及putchar()输出字符。通过示例代码展示了直接输出字符以及转换为ASCII码输出的方法。
最低0.47元/天 解锁文章
1526

被折叠的 条评论
为什么被折叠?



