Re: List
Michael wrote:
Ok now I try:
list<char> charList;
Please consider.
char c = 'a'; // c is a variable of type char
// it can contain a value of one char.
charList is a std::list of type char, each element (or member or
whatever terminology we'll use) can contain one character.
char* arp = "Test1";
arp is a point to char. A char* can point to a single character or
a zero terminated string or if you've rolled your own string handling
function perhaps something else. In this case it is pointing to a region
in memory that contains the characters 'T', 'e', 's', 't', '1', '\0'
sequentially.
if (something)
charList.push_back(*arp);
Assuming that something is true, charList isn't empty anymore and has an
element that contains the value 'T'. This will become clearer if you
will...
// Display the list
Here's a little program to do that. I didn't copy and paste, so be careful.
#include <iostream>
#include <list>
int main() {
std::list<char> cl;
const char *p1 = "Test";
const char *p2 = "Help";
cl.push_back(*p1); // 'T'
cl.push_back(*p2); // 'H'
for(std::list<char>::const_iterator i=cl.begin(); i!=cl.end(); i++) {
std::cout << *i << std::endl;
}
}
Ought to output:
T
H
and not
Test
Help
list<char>::iterator theIterator;
for( theIterator = charList.begin(); theIterator != charList.end();
theIterator++ ) {
I found this, http://www.xsquawkbox.net/xpsdk/mediawiki/XPLMDrawString
So yes, it looks like you want to pass a char* as the fourth parameter.
XPLMDrawString(white, Panel1WindowLeft + 20, Panel1WindowTop - 20,
theIterator, 0, xplmFont_Proportional);
}
Consider,
#include <iostream>
#include <list>
void someFakeFunction(char *p) {
std::cout << p << std::endl;
}
int main() {
std::list<char*> cl;
char *p1 = "Test";
char *p2 = "Help";
cl.push_back(p1);
cl.push_back(p2);
for(std::list<char*>::iterator i=cl.begin(); i!=cl.end(); i++) {
someFakeFunction(*i);
}
}
Ought to output
Test
Help
I don't particularly care for this for several reasons. I think you
ought to consider using std::string. You might have to write a wrapper
or some sort of smart pointer to get a non-const pointer to char.
Since you indicated earlier in the thread that each of these "Test?"
strings has an associated flag, you may wish to look into std::pair.
You could make a list like std::list< std::pair<bool, std::string> >.
Although it's not clear to me why you're using a std::list and not a
std::vector. Or maybe even just an array.
Also, your use of magic numbers,
XPLMDrawString(white, Panel1WindowLeft + 20, Panel1WindowTop - 20,
seems a bad thing to me. In the case of your loop above, it looks like
you will draw over the same space. Your original code changed the
offsets for each item, also using magic numbers, but might have left
spaces if a particular text wasn't going to be drawn.
I get the error:
cannot convert ?std::_List_iterator<char>? to ?char*? for argument ?4?
to ?void XPLMDrawString(float*, int, int,
char*, int*, XPLMFontID)?
Many thanks for help
I think you can get the compilation error to go away if you change
theIterator
to
&*theIterator
but you will very likely have problems at run time since I suspect the
function you're calling expects a zero terminated string and your list
is of type char.
LR