不只打印所有字母,而是需要在输入后打印出每个字母
not printing out all alphabet just one letter but it needs to print out every letter after the one that was entered
到目前为止,它只是在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;
}
相关文章:
- 打印时有二叉树问题.用户输入不打印任何内容
- 为什么有时我输入一个整数,程序将第一个输入的数字打印成十进制数?
- 我要求用户输入大小和数组,但是当我打印矢量时,它仅显示'0'作为输出
- 如何打印不带空格的输入整数?
- 为什么无论输入如何,所有 if-else 语句都会打印?
- 使用用户输入打印 6X10 矩阵的代码 - C++
- 如何使用打印到 PDF 打印机在 MFC 和 CView 中以编程方式打印而不提示输入文件名?
- 如何打印输入值
- 带有用户输入的C 文本数组,然后打印输入
- 读取和打印输入和 C 字符串C++
- 如何打印输入而不将其存储在c++中
- SFML—创建游标并打印输入
- c++的新功能,scanf不能正确读取/打印输入
- 如何打印输入的第一个数字?
- 如何自动打印输入的c++函数参数值
- C++:为什么 getline() 不打印输入字符串的最后一个单词?
- 打印输入的最小数字(不包括任何负数)
- 创建一个控制台应用程序,打开TCP/IP连接并用C++、C#或Java打印输入的字符串
- 从文件打印输入数据
- 按倒序打印输入字符串