getchar()的浅理解
#include<iostream>using namespace std;void test01(){char b;//getchar()一次只读一次字符while ((b = getchar()) != '\n') //对b依次输入且依次输出cout << b << "\t";//输入12 445输出12445}void test02(){char b =
·
#include<iostream>
using namespace std;
void test01()
{
char b;
//getchar()一次只读一次字符
while ((b = getchar()) != '\n') //对b依次输入且依次输出
cout << b << "\t"; //输入12 445 输出1 2 4 4 5
}
void test02()
{
char b = getchar(); //对b依次输入但只保留首个字符
//这时候b的值只有输入的第一个字符,因此下面会进入死循环
//while (b != '\n')
//cout << b << "\t";
}
int main()
{
//test01();
test02();
system("pause");
return 0;
}
`
更多推荐
已为社区贡献1条内容
所有评论(0)