| View previous topic :: View next topic |
| Author |
Message |
chammer n00b


Joined: 19 May 2003 Posts: 43 Location: Newport News, VA
|
Posted: Sun May 25, 2003 7:40 pm Post subject: c++ type conversion |
|
|
been a very long time since i've programmed in c/c++, but im back at it. have a problem though with some type conversions. basically my code looks like this... (doing qt/kde programming btw)...
string local_line = line; /* line gets passed to the sub via void blah (char *line) */
string lcd_text = local_line.substr (12, 4);
lCDNumber21->display (lcd_text); /*has to be const QString*/
this all works fine. the problem then becomes...
/* this doesnt work, it errors out no matter how many differnt type conversions i try */
progressBar11->setProgress (lcd_text); /* has to be int */
i've tried what i thought would be the right way ala:
int blah = atof (lcd_text);
but this fails. also i've tried making lcd_text not a string, but a char *...this fails trying to assign the substr to it, however. tried dozens of different ways, with no luck.
i know this is very sparse, but any ideas? _________________ http://www.nasland.nu
echo '[q]sa[ln0=aln256%Pln256/snlbx]sb3135071790101768542287578439snlbxq' | dc
echo '16i[q]sa[ln0=aln100%Pln100/snlbx]sbA0D4D465452snlbxq' |dc |
|
| Back to top |
|
 |
dma Guru

Joined: 31 Jan 2003 Posts: 437 Location: Charlotte, NC, USA
|
|
| Back to top |
|
 |
chammer n00b


Joined: 19 May 2003 Posts: 43 Location: Newport News, VA
|
Posted: Sun May 25, 2003 8:56 pm Post subject: thanks... |
|
|
thanks for the qstring doc, it actually lead me to something. since i usually try first thing that comes to mind versus thinking about doing something the right way (only 75% of the time ) i ended up just copying what i needed to QString. so...
string blah = hello.substr (12, 4)
..etc etc..
QString temp = blah;
double d = atof (temp);
int i = atoi (temp);
i needed the double for the float (maybe i can just use an int instead?...its been way to long...).
anyways, this is what i was building, i was stuck on that problem for the past 3 hours while searching/researching via google and my c++ books. glad i stopped here though. anyways...
[img:53c5e15ecd]http://www.nasland.nu/nst.png[/img:53c5e15ecd]
(the progress bars are based off a set limit. 65C in this case. just to give you another way of interpreting the degrees.)
was initially going to do this in QtPerl (im a perl monger ) or GTK (i also love GTK), but i figured should anyone want this it'd prolly be best to be as native as possible and i've yet to build a Qt/KDE application in all my years under a Unix flavor. its built around lm_sensors, so...as long as you have lm_sensors and qt...it should run. if anyone wants to give it a try let me know and i'll tar up the source and upload it to me site. _________________ http://www.nasland.nu
echo '[q]sa[ln0=aln256%Pln256/snlbx]sb3135071790101768542287578439snlbxq' | dc
echo '16i[q]sa[ln0=aln100%Pln100/snlbx]sbA0D4D465452snlbxq' |dc |
|
| Back to top |
|
 |
chammer n00b


Joined: 19 May 2003 Posts: 43 Location: Newport News, VA
|
Posted: Mon May 26, 2003 12:23 am Post subject: |
|
|
updated it a bit in case anyone is interested...
[img:e715ce3dfd]http://www.nasland.nu/nst4.png[/img:e715ce3dfd]
added the fan speeds and removed the progress bars (they were only getting in the way)  _________________ http://www.nasland.nu
echo '[q]sa[ln0=aln256%Pln256/snlbx]sb3135071790101768542287578439snlbxq' | dc
echo '16i[q]sa[ln0=aln100%Pln100/snlbx]sbA0D4D465452snlbxq' |dc |
|
| Back to top |
|
 |
far Guru


Joined: 10 Mar 2003 Posts: 394 Location: Stockholm, Sweden
|
Posted: Sat May 31, 2003 9:42 pm Post subject: |
|
|
A more modern way to convert a string to a number:
| Code: | #include <sstream>
#include <iostream>
int main() {
using namespace std;
stringstream foo;
string bar("4711");
int baz;
foo << bar; foo >> baz;
cout << bar << " == " << baz << endl;
return 0;
} |
_________________ The Porthole Portage Frontend |
|
| Back to top |
|
 |
|