|
Hi All,
How does one use cout to display hex characters?
For example a variable is set to 0x60, but when you call cout << var << endl; you get ' because that is 0x60 on the ASCII table.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
The old fashion (C) way:
int i = 0x60;
printf("%02X", i); // prints "60"
printf("%04X", i); // prints "0060"
|
|
|
|
|
Hi !
I put some sample code for your. You can make use of it, as per your need.
int n=20;
cout << "decimal: " << n << endl;
//--- Print hex with leading zeros
cout << "hex : ";
for (int i=2*sizeof(int) - 1; i>=0; i--)
{
cout << "0123456789ABCDEF"[((n >> i*4) & 0xF)];
cout << endl << endl;
}
-Malli...!
|
|
|
|
|
Hi,
That is rather cute code!
Thanks,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Why not use:
cout << std::hex << var << endl;
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
I have to agree with David, why not stick to the iostream idioms to do the trick. Although if 'var' is defined as type 'char' then you'll need to be a little sneaky since the formatting specifier hex modifies the output base of int's but does not modify the formatting of char's.
<br />
<br />
#include <iostream.h><br />
#include <iomanip.h><br />
<br />
<br />
char var = 0x60;<br />
<br />
cout << hex << var << endl;
<br />
cout << hex << (int) var << endl;
<br />
<br />
cout << hex << setw(2) << setfill('0') << (int) var << endl;<br />
<br />
Remember kids, we're trained professionals. Don't try this at home!
|
|
|
|
|
I want make SQL operation(Add, Modify, Delete records) to Access using ODBC.
I found many method to done(ADO, CRecordSet ), but which one is good for using ?
Can give me some suggestion about ODBC connect to Access in VC++ 6?
Thanks
|
|
|
|
|
One of the simplest methods is to create a DSN for your Access database. Then use ClassWizard to create a CRecordset -derived object. It will ask you which DSN to use. You can then select the tables and columns to use. See here for an example.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
Can i directly using ODBC connection strings and write the database location (like C:\testing\testingdb.mdb) in the ODBC connection strings ?
Because DSN need setting it before using.
Thanks your reply.
|
|
|
|
|
Sure. That same article shows how to use a DSN-less connection.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
I want to perform some action whenever folder selection occured.So, I want to catch the Shell View(List View) events.Plz send any material or code regarding this topic.
|
|
|
|
|
Hi,
In my application i have two views say View1 and View2. When the data in the document changes each view is notified synchronously. But if i hover mouse over the view2 when the the data in document is changing and the notification is not yet sent a event is fired by mouse hover even though i have used CWaitCursor in document. I need to prevent this as its trying to access the old data when new data is loading.
Any help please..
Thanks in advance..
Nithya..
|
|
|
|
|
Any one help me to solve this problem I used ISNetworkAlive to check my lan network connection status but it is not working. Also I used NetServerEnum it is also not working in some systems . Any one please sugest me an alternative method. any status chane message is there.
|
|
|
|
|
Aby Skaria wrote: Any one please sugest me an alternative method.
See here.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
Aby Skaria wrote: ny one please sugest me an alternative method. any status chane message is there.
http://support.microsoft.com/?id=321381[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
I have removed all extended styles and WS_BORDER style to get rid of the raised border around the progress.
But this doesn't seem to work. Can somebody help?
Owner drawn
Jesus Loves
|
|
|
|
|
hello... I'm kinda new in using visual C++ in a relational database. I would just like to ask help if someone has a sample code for connecting updating and closing a database. An ADODC or a DAO will work fine with me. Thanks...
--------------------------------Life is simple, You just complicate things----------------------------
-- modified at 1:44 Wednesday 15th February, 2006
|
|
|
|
|
tell the adjectly how u want to connect..
Through ODBC , DAO or .. any other way..
Then i will send u a sample code for that
Ashutosh
|
|
|
|
|
I'm using ADODC. But you could send me an example for a DAO. I'm choosing from the two. And i'm a little bit confuse...
-----------------------------------Life is simple, You just Complicate Things-----------------------------
|
|
|
|
|
Sample Code for DAO-----> Try this--->
CString csQuery; -->à SQL Query
CsaoDatabase pUserDB = new CDaoDatabase();
//Open DataBase in Read Only Mode
m_pUserDB->Open(Path_of_Database,FALSE, TRUE, _T(""));
CDaoRecordset m_pDaoUserRS = new CDaoRecordset(m_pUserDB);
m_pDaoUserRS->Open(AFX_DAO_USE_DEFAULT_TYPE,csQuery,dbReadOnly);
COleVariant varValue;
m_pDaoUserRS->GetFieldValue("Field_Name_of_Database",varValue);
Ashutosh
|
|
|
|
|
moodsey211 wrote: An ADODC...
Isn't that a VB thing?
Anyway, see here.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
In my code i have a situation like..
char * getmestring()
{
char *str = new char[20];
str = "myname";
return str; --> str not at all release..
}
int main()
{
char name = getmestring();
cout<<name<<endl;
if(name="" !="NULL)"
="" {
="" delete="" []="" name;="" --=""> this is causing the debug assertion failed..
}
}
can u give me some idea to remove leaks in that piece of code..
nagesh
-- modified at 0:40 Wednesday 15th February, 2006
|
|
|
|
|
char *name = getmestring();
cheerz!
dont want,dont want thinking,climbing on head and jumping grass!
(venda venda ennu vicharikumbol thellayill keyaree chadunnoda pulle!)
|
|
|
|
|
naguu wrote: char * getmestring()
{
char *str = new char[20];
str = "myname";
return str; --> str not at all release..
}
The memory you allocate with the new statement isn't being used at all. The "str = "myname"; " line doesn't copy the string; it copies over the address of the memory you allocated with new with the address of the string literal "myname".
This is probably what you mean:
char * getmestring()
{
char *str = new char[20];
strcpy(str, "myname");
return str; --> str not at all release..
}
Steve
|
|
|
|
|
Try this ................
int main()
{
char *name = getmestring(); --> modify this line
cout<<name<<endl;
if(name !="NULL)
{
" name="NULL;" ---=""> Add this line
delete [] name; --> this is causing the debug assertion failed..
}
}
Inform me if success...
Ashutosh
|
|
|
|