From: rketcham <Ric...@gm...> - 2007-09-06 21:45:45
|
Hi,=20 I'm having a slight problem with some code I wrote for the gumstix in c++. Essentially, I want to take in numeric values from a sensor node and conver= t those values to a string. On my Ubuntu platform, it works fine. This is the printout: Enter the Basestation's com port number to use: 0 open_port: Port /dev/ttyUSB0 was opened successfully. insert into LDC448 (TimerTick,NodeAddress,ChannelData) values (80,448,8190) insert into LDC448 (TimerTick,NodeAddress,ChannelData) values (81,448,8190) The numbers 80 448 and 8190 were correctly converted to strings.=20 However, when I compiled it using the c++ cross-compiler and then used it o= n the gumstix (via ssh), it didn't quite work so smoothly. Here's the printout: Enter the Basestation's com port number to use: 0 open_port: Port /dev/ttyUSB0 was opened successfully. insert into LDCX=EF=BF=BD (TimerTick,NodeAddress,ChannelData) values (X=EF= =BF=BD,X=EF=BF=BD,X=EF=BF=BD) insert into LDC=EF=BF=BD=EF=BF=BD! (TimerTick,NodeAddress,ChannelData) valu= es (=EF=BF=BD=EF=BF=BD!,=EF=BF=BD=EF=BF=BD!,=EF=BF=BD=EF=BF=BD!@) Here's the gist of the program: std::string s; s=3D"insert into LDC"+stringify(ldcPacket.nodeAddress)+" (TimerTick,NodeAddress,ChannelData) values (" + stringify(ldcPacket.timerTick) + ","+ stringify(ldcPacket.nodeAddress)+ ","= + stringify(ldcPacket.channelData.back())+")";=09 cout<<s<<endl; where stringify is this function: //Convert a number to string using a string stream inline std::string stringify(double x) { =09std::ostringstream o; =09o<<x; =09return o.str(); } This is what's included: #include <iostream> #include <exception> #include <limits> #include <sqlite3.h> //sqlite version 3 #include <string>//Added Okay. During the process of writing the above, I managed to fix the problem by doing the following: std::stringstream s; //SQL string s<<"insert into LDC"<<ldcPacket.nodeAddress<<" (TimerTick,NodeAddress,ChannelData) values ("<<ldcPacket.timerTick<<","<<ldcPacket.nodeAddress<<","<<ldcPacket.channel= Data.back()<<")";=09 cout<<s.str()<<endl; If any of you know why this worked and not what I had above, please let me know. Thanks, Rich --=20 View this message in context: http://www.nabble.com/C%2B%2B-coding-on-gumst= ix-tf4394863.html#a12532101 Sent from the Gumstix mailing list archive at Nabble.com. |