Hi
imagine a display where new values are added at the bottom line. If a
value gets untrue that line disappears and all below move up one line.
So list might be the easiest to use? i need to draw something alike:
if (8value == 1)
{
XPLMDrawString(white, PanelWindowLeft + 20, PanelWindowTop + 20,
"Test8", 0, xplmFont_Basic);
}
if (7value == 1)
{
XPLMDrawString(white, PanelWindowLeft + 20, PanelWindowTop + 10,
"Test7", 0, xplmFont_Basic);
}
if (9value == 1)
{
XPLMDrawString(white, PanelWindowLeft + 20, PanelWindowTop + 30,
"Test9", 0, xplmFont_Basic);
}
etc.
Now how could i have them dynamically moving up/down on true/untrue? ie.
pack this into a list?
Many thanks
Michael
|
|
0
|
|
|
|
Reply
|
Michael106 (11)
|
1/1/2011 7:40:21 AM |
|
Ok now I try:
list<char> charList;
char* arp = "Test1";
if (something)
charList.push_back(*arp);
// Display the list
list<char>::iterator theIterator;
for( theIterator = charList.begin(); theIterator != charList.end();
theIterator++ ) {
XPLMDrawString(white, Panel1WindowLeft + 20, Panel1WindowTop - 20,
theIterator, 0, xplmFont_Proportional);
}
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
|
|
0
|
|
|
|
Reply
|
Michael
|
1/2/2011 1:07:11 PM
|
|
On Jan 2, 1:07=A0pm, Michael <Mich...@notspam.com> wrote:
> Ok now I try:
>
> =A0 =A0 =A0list<char> charList;
>
> =A0 =A0 =A0char* arp =3D "Test1";
>
> =A0 =A0 =A0if (something)
> =A0 =A0 =A0 =A0 =A0charList.push_back(*arp);
>
> =A0 =A0 =A0// Display the list
> =A0 =A0 =A0list<char>::iterator theIterator;
> =A0 =A0 =A0for( theIterator =3D charList.begin(); theIterator !=3D charLi=
st.end();
> theIterator++ ) {
> =A0 =A0 =A0XPLMDrawString(white, Panel1WindowLeft + 20, Panel1WindowTop -=
20,
> theIterator, 0, xplmFont_Proportional);
> =A0 =A0 =A0}
>
> I get the error:
> cannot convert std::_List_iterator<char> to char* for argument 4
> to void XPLMDrawString(float*, int, int,
> =A0 char*, int*, XPLMFontID)
> Many thanks for help
compilers do their best to help you. The function wants a char* (a
pointer to a char) theIterator isn't a char* it's a
list<char>::iterator. To convert it you use the dereference operator
that is defined for list iterators.
XPLMDrawString(white, Panel1WindowLeft + 20, Panel1WindowTop -
20,
*theIterator, 0, xplmFont_Proportional);
|
|
0
|
|
|
|
Reply
|
Nick
|
1/2/2011 1:15:56 PM
|
|
Yes, that would be? * theIterator
And i get:
- invalid conversion from �char� to �char*�
Thanks again
|
|
0
|
|
|
|
Reply
|
Michael
|
1/2/2011 4:03:59 PM
|
|
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
|
|
0
|
|
|
|
Reply
|
LR
|
1/2/2011 8:37:59 PM
|
|
list<char> charList;
char *arp = "TEST0";
charList.push_back(*arp);
// Display the list
list<char>::iterator theIterator;
for( theIterator = charList.begin(); theIterator != charList.end();
theIterator++ ) {
XPLMDrawString(white, Panel1WindowLeft + 20, Panel1WindowTop - 20,
&*theIterator, 0, xplmFont_Proportional);
}
Many thanks. The above works but draws only T. Any idea on how to draw
all "TEST0"?
Funny, never seen: &*theIterator
before in my short C++ life...
|
|
0
|
|
|
|
Reply
|
Michael
|
1/3/2011 9:33:53 AM
|
|
Michael wrote:
> list<char> charList;
> char *arp = "TEST0";
> charList.push_back(*arp);
>
> // Display the list
> list<char>::iterator theIterator;
> for( theIterator = charList.begin(); theIterator != charList.end();
> theIterator++ ) {
> XPLMDrawString(white, Panel1WindowLeft + 20, Panel1WindowTop - 20,
> &*theIterator, 0, xplmFont_Proportional);
> }
>
> Many thanks. The above works but draws only T. Any idea on how to draw
> all "TEST0"?
You're not storing all of "Test0" in your list. Only the 'T' since
you're using a std::list<char>. I think you got lucky that you only
showed the 'T' and not something like "Tl939wio923i1-0(**(&&*^".
Please review the post that you're replying to and take a look at the
example with std::list<char*> I don't like it because I think it will
cause more problems than it will cure.
Consider making a small string class of your own, put it in a namespce
that makes sense for you, give it a method that returns a non-const char
*. Make your list of this class.
> Funny, never seen: &*theIterator
> before in my short C++ life...
Take the address of the instance of char that theIterator 'points' to.
I'm still not clear on why you're using a list.
You might be better off trying this without the call to XPLMDrawString.
At first write a program that just writes the data to std::cout to see
what you get.
LR
|
|
0
|
|
|
|
Reply
|
LR
|
1/3/2011 9:19:18 PM
|
|
Now if i try:
do{
charList.push_back(*arp);
}while(*arp);
I get an endless loop. How should i do that?
Many thanks again
Michael
|
|
0
|
|
|
|
Reply
|
Michael
|
1/4/2011 7:55:32 AM
|
|
Michael wrote:
> Now if i try:
>
>
> do{
> charList.push_back(*arp);
> }while(*arp);
>
>
> I get an endless loop. How should i do that?
I don't know why you would want to do this.
Consider making an array of pointers to char,
char *a[]
and using a for loop to index through the array.
Try initializing the array and printing out all the values.
Are you using a book?
What compiler are you using?
LR
|
|
0
|
|
|
|
Reply
|
LR
|
1/4/2011 8:29:40 AM
|
|
If I try something alike:
list<char> charList;
char displayTxt[50];
displayTxt[0]= "Test1";
for (int i =1; i <= 50; i++)
charList.push_back(displayTxt[i]);
I get: invalid conversion from �const char*� to �char
> I don't know why you would want to do this.
>
I want a display. New values are added at the bottom. Untrue values are
not displayed anymore and all values below are moved one position up:
Panel1WindowTop - 20 // draw position
etc.
> Consider making an array of pointers to char,
> char *a[]
> and using a for loop to index through the array.
>
> Try initializing the array and printing out all the values.
>
>
> Are you using a book?
>
Jesse liberty c++ in 21 days.
> What compiler are you using?
GCC Linux and Mac later also VC.
Thanks again
Michael
|
|
0
|
|
|
|
Reply
|
Michael
|
1/6/2011 7:58:32 AM
|
|
Michael <Michael@notspam.com> wrote:
> If I try something alike:
>
> list<char> charList;
> char displayTxt[50];
> displayTxt[0]= "Test1";
>
> for (int i =1; i <= 50; i++)
> charList.push_back(displayTxt[i]);
>
> I get: invalid conversion from �const char*� to �char
Of course you are, but the error has nothing to do with the charList
variable. The offending line is:
displayTxt[0]= "Test1";
'displayTxt[0]' is of type 'char' and "Test1" is of type 'const char*'.
You can't convert from const char* to char, hence the error.
|
|
0
|
|
|
|
Reply
|
Daniel
|
1/6/2011 1:20:01 PM
|
|
Michael wrote:
> If I try something alike:
>
> list<char> charList;
> char displayTxt[50];
> displayTxt[0]= "Test1";
As was pointed out by Daniel T elsethread the above is the cause of the
error message you're getting below.
displayTxt[0] = 'T';
displayTxt[1] = 'e';
displayTxt[2] = 's';
displayTxt[3] = 't';
displayTxt[4] = '1';
displayTxt[5] = '\0';
would do what I think you would like your assignment statement to do.
A char is only a single character. It doesn't contain a string of
characters. Very loosely speaking, "Test1" is like an array of char
somewhere in memory. That is, a string is sort of like an array of char.
char x[10]; doesn't mean an array of ten strings, but an array of ten char.
Consider trying this snippet,
char s[] = "hello";
std::cout << s << std::endl;
s[2] = 't';
std::cout << s << std::endl;
>
> for (int i =1; i <= 50; i++)
> charList.push_back(displayTxt[i]);
You'll end up with a list of char with one character in each member of
the list.
>
>> I don't know why you would want to do this.
>>
> I want a display. New values are added at the bottom. Untrue values are
> not displayed anymore and all values below are moved one position up:
>
> Panel1WindowTop - 20 // draw position
> etc.
At this point you seem to be doing more C style programming than C++,
even though you want to use std::list.
At some point you'll find the C++ faq useful, but at the moment you
might find more immediate help in the C faq.
http://c-faq.com/
http://c-faq.com/ptrs/index.html
http://c-faq.com/aryptr/index.html
The C++ faq is here
http://www.parashift.com/c++-faq-lite/
Also, IIRC Alf P. Steinbach who posts here frequently used to have a
pretty good tutorial posted somewhere online about C++ pointers. I
can't find it at the moment. Perhaps you should ask him if he'd be so
kind as to provide a link to it or resurrect it if it's not online at
the moment.
Please read up on std::string, it might save you some trouble.
>> Consider making an array of pointers to char,
>> char *a[]
>> and using a for loop to index through the array.
>>
>> Try initializing the array and printing out all the values.
This may still be worth trying as an exercise.
LR
|
|
0
|
|
|
|
Reply
|
LR
|
1/7/2011 6:53:35 AM
|
|
|
11 Replies
160 Views
(page loaded in 0.165 seconds)
Similiar Articles: Java Collections List : Converting from List 'I have a function that returns a list like this:- List > Next I want to pass this list to a 2nd function, but 2nd function just need= s a l... List of $PRP commands in SW notes? - comp.cad.solidworks ...Hello, I've recently been searching this group and found a lot of helpful info to save time in my title blocks such as the $PRP:"SW-Current Sheet" an... List Files By Date Range - comp.unix.programmerIs it possible to list a group of files by date range using UNIX command (i.e. ls -alt), script, awk, etc.? I just want to be able to retrieve a list... List of standard fonts (font names) in TeXLive? - comp.text.tex ...I'd appreciate a pointer to a downloadable list of all the standard Computer Modern fonts and Adobe "basic" fonts available for use in Plain TeX, ... List contents of file from war within ear - comp.lang.java.help ...Hi, I routinely receive ear files for deployment. Within the ear is a war file. Under the META-INF directory of the war file exists a file called ver... List supported display resolution ? - comp.os.ms-windows ...Hi, I need to get the list of resolutions supported by the user pc under windows (XP, Vista, 7). Is it possible without using a big sdk like directx... file list sorted by creation date - comp.lang.rubyHi, I need to get a list of all files in a directory sorted by their date/time of creation. Please help. -- Posted via http://www.ruby-forum.c... List connected dhcp clients - comp.dcom.sys.ciscoHi, I can't figure out how to list the computers connected to my Cisco 1720 router with dhcp enabled. I tried 'show dhcp lease', but it is not work... List pc supported screen resolutions ? - comp.os.ms-windows ...Hi, is it possible to simply list the resolutions supported by a pc (graphic card I suppose) in a c++ program ? Thanks ... List of static libraries - comp.unix.solarisHello, I have an executable built on a Solaris machine (version 5.7). It uses few static and few dynamic libraries. I used the "ldd " command and obt... List of Open GL 2.0 compatible GFX-Cards - comp.graphics.api ...Hi NG, where can I find a list of Open GL 2.0 compatible GFX-Cards ? cu Bodo ... Export field list to a file - comp.databases.filemakerI am using FMP 7 on Windows XP. Is there a way of exporting a list of my fields to a file? I know I can print a list but I would prefer to send the... Authorization list issue - comp.sys.ibm.as400.miscOn the Display Authorization List (DSPAUTL) screen, F15 will display a list of objects secured by the authorization list. When I attempted to use... Tag List Protected error - comp.soft-sys.math.mathematica ...Hi, I am trying to use ReplacePart in a function definition. The function works using =, but not := newX= ReplacePart[x,{y[[1, 1]], y[[2, 1]]} ... Get list of computers in workgroup using C? - comp.os.ms-windows ...Hoping for help! I have a leagacy C program (not .net), which is currently sending "net view" via a system() call, writing to a file, then reading... craigslist: los angeles classifieds for jobs, apartments ...craigslist provides local classifieds and forums for jobs, housing, for sale, personals, services, local community, and events Craigslist > CitiesList of all international craigslist.org online classifieds sites 7/4/2012 10:01:07 PM
|