(Apologies; sent wrong place; now right place: here.)
On Feb 10, 5:17 pm, "John Brawley" <jgbraw...@charter.netwrote:
"John Brawley" <jgbraw...@charter.netwrote in message
[...]
I'll think about it more but probably take your suggestions
and use doub-quotes around every line. It'll be 'uglier' to
me in the .cpp file, but I'd just as soon do things "the right
way" whenever possible.
I'm curious. Why uglier? Your solution doesn't allow
indentation of any but the first line---using separate string
literals (concatenated by the compiler) does.
Of course, if this is really a more or less large body of text
that you want to maintain as text, the best solution is to do
just that---maintain it as text, in a separate file. If you
still want to have it "compiled into" your program (there are
pros and contras to this), then a simple preprocessor will
convert it to a C style array. Something like:
#! /usr/bin/awk
BEGIN {
print "// Automatically generated file"
print "// DO NOT EDIT"
print ""
print "#include \"helpText.hh\""
print ""
print "char const helpText[] ="
}
{
print " \"" $0 "\""
}
END {
print ";"
}
Then create (manually) the necessary "helpText.hh" header (which
is just one line), and the work is done.
(FWIW: I'd strongly recommend this. Maintaining text in a
format that has a C++ string literal per line will be a pain,
e.g. anytime one line gets to long, and you have to reformat the
paragraph. Whereas if the file is pure text, and the editor
recognizes it as such, it will do the reformatting for you.)
James Kanze
Hi James (and all).
These several last additions to the thread have me a bit confused....
Let me tell you what and why, then I will put in the actual function
that outputs the help file (you may have to unscramble if Usenet
linewraps)...
The program runs forever (user manually terminates).
The user can forget what keyboard keys are used to do whatever, and I
want him/her to _need_ to remember only the 'h' key. Thus the help page
needs to be in the executable thus in memory (yes, I want to
'distribute' one .exe file and a single .txt file).
All the lines of text look to me in the .cpp file, pretty much exactly
as they do on the console screen, with either the \ (continue on the
next line) or the " " double quotes-around, so I'm not sure what the
disagreement is about....
Here's the actual function, copied out of my working .cpp file:
void tvhelp() {
cout<<"\nKeyboard control keys (case is significant):\n\n"
"1,2,3,4,5, and [shift] 1,2,3,4,5 :\n"
"decrease or increase containment sphere radius by\n"
"0.1, 0.01, 0.001, 0.0001, 0.00001\n"
"r =manual ReScan NOW!; [shift]-R =turn off automatic reScan if on\n"
"s =write snapshot (.3D; view with Graph3D.exe) and .TVR files NOW!\n"
"p =write a PovRay file NOW!\n"
"h = this help screen (any time)\n"
"q =quit (end program; write final .3D and .TVR files); \n"
"[spacebar] =get a NOW! one-line pack status report containing:\n"
"pHi: greatest, pLo: smallest, pAvg: average, overlap,\n"
"gRad: present container radius, zC: per-piont overlaps, inner loop\n"
"Any other key: \"not a valid key\", (returns to the
rogram)\n\n\n"; }
(last line broke in emailer; don't know why; "returns to the
program"...)
I call it once at startup, so the user knows it's there and how to get
back to it, then it can be returned to the console screen by hitting the
'h' key (which control is inside a switch statement with all those above
case:es also....)
User is usually in "live" control, hitting the spacebar every now and
then, to judge the state of the packing by the info displayed, so he's
'right there' anyway.
So, does this (I guess this is its 'context'?) explain what/why better?
The console screen looks exactly like that, without the \n s and the
quote characters (and the C++ codewords, etc.)
It looked exactly like that also when using the continuation backslashes
instead, except the left hand side (continuation characters preserved
the indentations not present here). Six of one, half-dozen of the
other. This is a little "uglier" to me (all those quote " characters
instead of just two...)
Peace
JB
jb@tetrahedraverse.com
Web:
http://tetrahedraverse.com