Hi everyone,
I'm creating a program for which I want to create some basic, templated "starting" sequences. These are only run once and don't need to be fast, so readability is key. So far I've used a C-array, but I'd really like to use strings. So far I have this:
1 2
|
// header.h
const char* template_arr[];
|
1 2
|
// source.cpp
const char* template_arr[] = {"string 1","string 2","string 3","etc..."};
|
Naturally, I'm trying to learn c++, not c, so I really would prefer to use string arrays (I need to iterate through these later so that brings obvious issues too), but is it possible to create string arrays this neatly in c++?
To illustrate what I mean by "neat", here is an example of the actual string array:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
namespace Edhen
{
namespace GeneTemplate
{
const char* simple_ribosome[] = {
// first step is to go to a negative memory index and set the memory value to something positive
"IDXDEC", // go to mem index -1
"CLEAR","DROP","INC" // set memory value to 1
// next loop through every subsequent value (the input base sequence) forever (until output limit is reached)
"WHILEPOS", // while memory > 0
// move forward and output new memory pointer
"IDXINC", // increment memory pointer
"OUT", // return memory value
// now destroy the memory pointer and set it to something positive so that the loop continues
"TEN","DROP" // set the memory value to 10 (a positive number, doesn't matter which)
"END", // repeat the loop
"EOA", // declare end of array (for interpreter only - not included in base sequence)
};
}
}
|
The string arrays are actually "templates" for commands that should be written in a manner readable (including the indents) by a software engineer. My worry is that if I use something like
strvec.push_back("string")
at every line it's going to ruin the readability.
Is there any way to make string vectors in c++ as pretty and light-weight as in C?
Please note that in this instance performance is not a concern; these arrays are converted into function pointers and manipulated from there, so it's really just to provide a visually meaningful representation to the user.