c++ - 如何获得在 C++ 中生成字母表的更简单方法?

标签 c++ arrays project shortcut alphabet

我正在尝试制作一个项目,尝试和学习 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/

相关文章:

c++ - 像访问一维数组一样访问二维数组是否合法?

c++ - sql server 错误日志的输出错误

php - 为大型公司在 phpmyadmin 中创建大型 Web 应用程序

java - 使用 null 初始化字符串数组中的特定索引

JavaScript - 将数组转换为列表

project - GitLab 新项目设置 webhook

Java-SWT : How to update Label?

c++ - 意外的 undefined reference

c++ - 函数返回最大值的索引,跳过先前返回的值

php - 如何在 PHP 中检索 2 个标记之间的数组值?