|
Hi,
a 32-bit integer would have its bits numbered 0 to 31 from right to left.
their value corresponds to 1<<n where="" n="" is="" the="" bit="" number.
setting="" a="" accomplished="" with="" bitwise-or="" operator,="" symbol="" |
clearing="" bitwise-and="" &
warning:="" clearing="" done="" by="" keeping="" bits="" you="" do="" not="" want="" to="" be="" cleared,="" that="" complement="" of="" one(s)="" get="" rid="" of.
so="" following="" will="" change="" 5="" into="" 6:
<pre="">
int i=5;
int bit1=1<<1; // which is 2
int bit0=1<<0; // which is 1
i=i|bit1; // now i holds 7
i=i&~bit0; // keeping everything but bit0 yields 6
An alternative way of clearing a bit is first setting, then flipping it; flipping is handled by the bitwise-XOR, the symbol is ^.
i=5;
i=i|bit1;
i=(i|bit0)^bit0;
|
|
|
|
|
Hi All,
I am not able to Contents of File when it exceeds length of 1024.
CFile file;
if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead))
{
return false;
}
TCHAR buffer[100000];//say content is very Big
file.read(buffer,100000);
file.close();
I am not able to get the Contents into Buffer. But i am able to get the Length of the File
with int len = file.GetLength(). I am getting Junk into Buffer.
What may be the reason i am not able to get it into buffer.
Uday.
|
|
|
|
|
janaswamy uday wrote: file.read(buffer,100000);
You should always check the return value of an API function call.
See, for instance, the code sample in the _read documentation page[^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Try Using
CStdioFile .
Regards,
Paresh.
|
|
|
|
|
janaswamy uday wrote: if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead))
What you have posted will not even compile. That aside, this should be:
if (! file.Open("C:\\users\\rakesh\\Desktop\\myText.xml", CFile::modeRead))
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
janaswamy uday wrote:
if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead))
{
return false;
}
This means if you successfully open the file you return false instead of reading the file into your buffer.
I must get a clever new signature for 2011.
|
|
|
|
|
It may or may not be causing this issue, but the stack has limited space, and allocating 100,000 TCHARs on the stack is not a good idea.
you should instead use
LPTSTR buffer = new TCHAR[100000];
file.read();
delete []buffer;
|
|
|
|
|
Thank you very much Bruck. I will try with that.
|
|
|
|
|
I create a SDI project with VC 6.0.
I have to put
#include "testView.h"
in the file MainFrm.cpp, since I need to link testView to a splitted window pane using
wndSplitter_horizontal.CreateView(0,0,RUNTIME_CLASS(CTestView),CSize(50,50),pContext);
However, the compiler complaint with the following lines.
d:\vc_project\test\testview.h(27) : error C2143: syntax error : missing ';' before '*'
d:\vc_project\test\testview.h(27) : error C2501: 'CTestDoc' : missing storage-class or type specifiers
d:\vc_project\test\testview.h(27) : error C2501: 'GetDocument' : missing storage-class or type specifiers
The error can be replayed easily by creating a SDI project and typing in the MainFrm.cpp file
#include "TestView.h"
i have had a look online, but found no solutions.
modified on Friday, January 7, 2011 9:18 AM
|
|
|
|
|
You should include TestDoc.h as well since CTestView depends on it. In my opinion, that should have been taken care of in the TestView.h file, to make it self supporting. But sometimes compilation speed is preferred over ease-of-use.
|
|
|
|
|
Thank you for your reply.
when I create a SDI project with AppWizard,
I notice there are lines in the testView.h file
public:
CTestDoc* GetDocument();
but there is no #include "testDoc.h". The program works fine though.
However,when I simply put the line
#include "testView.h"
into the MainFrm.cpp file the error message pops up.
I think the error message is suppose to occur in the former case.
|
|
|
|
|
The reason it works fine in the first case is because in all files where testView.h is included (test.cpp and testView.cpp in a standard project), testDoc.h is included before testView.h.
#include "testDoc.h"
#include "testView.h"
So the advice to include testDoc.h first, is correct.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
|
i want to use bitmap image on button of media player usig active x contol
in mfc application
|
|
|
|
|
|
Hi,
This question is more from the point of view of Threads than C/C++. I have a destroy() function which waits on a thread (lets say _monitor) through PR_JoinThread(). The problem is that the _monitor thread has various time-oriented operations such as read()/write() socket calls so it takes time to finish off before exiting. Hence the destroy() function due to this PR_JoinThread which waits on the _monitor to exit is hanging the process (my product creates around 80-90 such threads) for around 6-7 minutes. Can anyone tell me the way to avoid such a situation? Is there any way other than using PR_JoinThread?
Thanks.
|
|
|
|
|
I don't know the api you are using (PR_JoinThread, google gives me something like NSPR API, whatever that might be) but generally if you don't want your "waiter thread" to block, you could either poll the other thread's state time to time, going on with your regular business in the meantime, or have somekind of messaging implementing with which the thread you would be waiting for can signal towards the waiter that it has finished processing, e.g. if you are working with VC++ you could use PostThreadMessage to send a message towards your GUI thread. Could this help?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <
>Nothing is free in the universe.<
|
|
|
|
|
Hi All,
Please let me know some hints to convert a hex value to a string..
Regards,
Spk521
|
|
|
|
|
Click here->[^]
I believe in LOVE AT FIRST SITE...
Bcoz I have loved my Mother...
even since I opened my eyes...(ICAN)
|
|
|
|
|
It depends what you mean by convert. Do you want the hex value to appear as hex in the string (e.g. 0x3739 --> "0x3739") or do you want to display it as characters (e.g. 0x3739 --> "79")?
I must get a clever new signature for 2011.
|
|
|
|
|
ys.. i need to convert hex to its corresponding ascii value...
|
|
|
|
|
Hi,
Please try this..
char str[] = "01-15-43-43-34-37-37-41";
char delims[]="-";
CString strAscii = _T("");
CString strModelN0 = _T("");
char *result= NULL;
result = strtok(str,delims);
while(result != NULL)
{
result = strtok(NULL, delims);
if(NULL != result)
{
strAscii.Format(_T("%c"),hexToAscii(result));
strModelN0 += strAscii;
}
}
char hexToAscii(char *Num)
{
char hex[10]= "0x";
strcat(hex,Num);
return strtol(hex, NULL, 16);
}
Regards,
Spidy
|
|
|
|
|
Thanks laj its working....
|
|
|
|
|
You missed the first number.
I must get a clever new signature for 2011.
|
|
|
|
|
in addition to his above example, if your hex is in some int type variable, you may try this also,
int k = 0x3739;
CString out;
while(k > 0) {
out += (char)k % 0x100;
k /= 0x100;
}
strrev(out.GetBuffer(0));
cout <<(LPCTSTR)out <<endl;
|
|
|
|