C++: Generate Lower Case ASCII Alphabet

Bjarne-stroustrup
 

Generate an array, list, lazy sequence, or even an indexable string of all the lower case ASCII characters, from ‘a’ to ‘z’.

If the standard library contains such sequence, show how to access it, but don’t fail to show how to generate a similar sequence. For this basic task use a reliable style of coding, a style fit for a very large program, and use strong typing if available.

It’s bug prone to enumerate all the lowercase chars manually in the code. During code review it’s not immediate to spot the bug in a Tcl line like this contained in a page of code:

set alpha {a b c d e f g h i j k m n o p q r s t u v w x y z}

C++ can do the task in the identical way as C, or else, it can use a STL function.

#include <string>
#include <numeric>

int main() {
	std::string lower(26,' ');

	std::iota(lower.begin(), lower.end(), 'a');
}

SOURCE

Content is available under GNU Free Documentation License 1.2.