不只打印所有字母,而是需要在输入后打印出每个字母

not printing out all alphabet just one letter but it needs to print out every letter after the one that was entered

本文关键字:打印 输入      更新时间:2023-10-16

到目前为止,它只是在a后打印出z,但是我希望它打印b c d e f g .... z

#include <iostream>
using namespace std;
int main() 
{
   char a = 'a';
   while (a < 'z')
   a++; 
  cout << a; 
}

im只是在寻找有关如何做的帮助,然后我需要输入2个字母并用2个字母来做,但这只是我知道这不是代码写作服务,而只是在寻找一些帮助怎么做。谢谢任何帮助是好

在循环中,您需要将多个语句包装在括号中:

int main() 
{
    char a = 'a';
    while (a < 'z'){
        a++; 
        cout << a; 
    }
    cout << 'n'; // let's have a line break at the end
}

否则cout语句仅一旦循环完成。

可悲的是,尽管此代码不是Portable ,因为C 标准对Alpha字符的编码方式的要求很少。它们的连续和连续并不是必需的。便携式解决方案基于表面上的明显

int main()
{
    std::cout << "abcdefghijklmnopqrstuvwxyzn";
}

;如果您想从中打印所有字母一个特定值,请在

的行上使用某些内容
int main() {
    const char* s = "abcdefghijklmnopqrstuvwxyz";   
    char a = 'k'; // print from k onwards, for example
    for ( ; *s /*to prevent overrun*/ && *s != a; ++s);     
    std::cout << s; 
}

需要将cout放入循环中:

#include <iostream>
int main() 
{
   char a = 'a';
   while (a < 'z')
   {
      a++; 
      std::cout << a << " "; 
   }
}

还增加了一个区分不同字母的空间。并删除using namespace std;,因为不建议进行。

唯一在a 中执行的东西;因为没有属于时的语句周围的括号。在括号中进行多个陈述。或者在这种情况下,可以使它们成为一个陈述。

#include <iostream>
int main() 
{
    char a = 'a';
    while (a < 'z')
        std::cout << ++a;
}