用putchar在屏幕上打印字符
printing character on screen with putchar
void main ()
{
char ch='A';
while (ch <='F'){
switch (ch){
case 'A':
case 'B':
case 'C':
case 'D': ch++; continue;
case 'E';
case 'F': ch++;
}
putchar (ch);
}
我的问题是,为什么程序的输出仅是FG,为什么它不打印字母E(EFG)。而且,为什么putchar打印两个字符的定义是在屏幕上只有一个字符时,为什么要打印两个字符。
在案例E方面,因为没有休息;在该语句之后,它将在Switch语句中执行所有情况,从而执行CH ;案件f e 是f,所以putchar将打印f接下来,因为您的条件在while语句中较小或等于f,它将再次输入开关 如果f它将再次执行CH 现在CH拥有G和Putchar Prints G的值GG是不少或相等的F,它将退出时循环并结束。因此,您已经打印了F。
为什么不打印e的问题,请查看我在此处对您的代码的评论:
void main ()
{
char ch='A';
while (ch <='F'){
switch (ch){
case 'A': // ch: A=>B; continue;
case 'B': // ch: B=>C; continue;
case 'C': // ch: C=>D; continue;
case 'D': ch++; continue; // ch: D=>E; continue; | E isn't printed here "continue" is called instead.
case 'E'; // ch: E=>F; putchar(F); | E isn't printed here either F is printed because F is assigned just before "putchar" is called.
case 'F': ch++; // ch: F=>G; putchar(G);
}
putchar (ch);
}
第二个问题,为什么PutChar打印两个字符:不是。它每次仅将一个字符写入输出缓冲区,但输出缓冲区写在晚期呼叫的屏幕上。
putchar后使用std::cout.flush()
立即显示您的输出。
还将case 'E';
更改为case 'E':
以使您的代码编译,请。
相关文章:
- 打印字符数组地址的正确方法
- c ++控制台应用程序,如何在控制台外部打印字符
- 无法使用 swprintf 在 WCHAR* 中打印字符*
- 存储和打印字符,但输出不是预期的
- 如何使 printf 以与 NSLog 相同的方式打印字符缓冲区?
- 在带有 (void*) 强制转换的字符串中打印字符的内存地址
- C++无法打印字符变量
- 无法打印字符向量C++向量
- 为什么在编辑 fastq 文件并将输出写入新的 fastq 文件时引入不可打印字符?
- C :如何询问文件名并打印字符数组
- 循环中的 Cout 不会按定义的字符逐个打印字符
- (C++) 打印字符数组字符串的单词时出现问题
- 用putchar在屏幕上打印字符
- 在C 中使用继续语句的打印字符
- 在 for 循环 c++ 中打印字符
- 使用while和if递归打印字符
- 打印字符数组 c++
- 如何使用Xcode中的Unicode打印字符╔(和其他字符)
- cout.put() 是否推荐使用 cout<< 打印字符
- C++ 中的密码 |打印字符后删除字符