我正在尝试制作一个项目,尝试和学习 C++,我还没有完成它,但是它的作用是您输入 3 或 4 个(变量 noc)单词,程序运行所有可能的(noc)字母单词或废话,直到找到你的,所以有两个因素:单词或废话的长度以及它可以输入的字符,在我的情况下,我只想要字母表
所以这是我的代码:
#include <iostream>
#include <unistd.h>
using namespace std;
const int noc = 3;
int main() {
string used[noc];
string inp;
cin >> inp;
char albet[] = {'a','b','c'};
cout << "Starting..." << endl;
usleep(1);
string aiput = "";
while(aiput != inp){
for(int i = 0; i <= noc; i++){
aiput = aiput +
}
}
return 0;
}
目前我需要名为“albet”的数组中的字母表(我想出了简短的词来表达它们的意思,很容易忘记)
所以请你给我一种在 C++ 中快速生成字母表的方法,而不是一个一个地输入所有字母
最佳答案
当您需要一个字符数组时,您不必一一使用单个字 rune 字,如
char albet[] = {'a','b','c','d','e','f',... uff this is tedious ...};
您可以改用字符串文字:const std::string albet{"abcdefghijklmnopqrstuvwxyz"};
我花了大约 10 秒的时间输入并与其他答案相比,这不依赖于 ASCII 编码(不能保证)。
关于c++ - 如何获得在 C++ 中生成字母表的更简单方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62006349/