|
|
Use the pow function defined in math.h .
|
|
|
|
|
Unfortunately he cannot use pow(2, 12345) , because the result is bigger than the maximum number that a float and double can hold.
Anyway, when I see question like this one, I think that the enquirer is interested in big integer arithmetic required for some cryptographic ciphers (like RSA).
Have a look to this links, I think it could be helpfuf:
bigint c++ Google search[^]
|
|
|
|
|
Big integers?? I 2^12345 is (in binary) 1 followed by 12345 zeroes (1544 bytes!)... And probably that's just the answer.
If he have to estimate the value, 2^12345 is 10^(12235/Log10(2)) =
10^3716.
If the ^ is instead the XOR operator ... the result is 12347 (divide by 2, add one if even o subtract one if odd, and multiply by 2)
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
You are right! 2^12345 is simply 1 followed by 12345 zeroes and it is equal to 10^(12345/Log10(2))
I spoke about big integer libraries because I think that the enquirer is asking about "how to keep in memory numbers with this kind of size, and how to make calculations with them"...
|
|
|
|
|
How to control the size of the text file that we want to write in and create another file if it passes our limit in vc++??
i.e: Assume that we put the incoming messages to a logfile.txt, as soon as its size got bigger than 10mb, we must create another file, name logfile(2).txt and continue writing on this.. this goes like this...
|
|
|
|
|
Get the size of the file when opening the file.
Keep adding the size of data being written.
When the size exceeds the limit open another file and reset the size variable to 0.
|
|
|
|
|
If you mean: how to know the size, you can either simply have a counter which you increase by the length of the text written to the file each time and then after of before writing the text check it if it exceeds your limit and then close the current file and create the new one. Or you can use ftell[^] or SetFilePointer[^] (or somesuch, depending on how you handle the file) to query the file pointer and if it is above a certain position, again, close the current file and open a new one.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
With GetFileSize()[^] you can get the size of a specified file (on Windows) and with some program logic around you will be able to write to multiple log files.
Hope this helps
|
|
|
|
|
please check size of file before write the data in to file and if data is greater than your limit of size then create another file.
|
|
|
|
|
Dear All,
Very Good morning.
I am facing some conceptual doubts in post increament and pre increament operators in for loop.
Kindly follow the code below:
for(int i=0;i<5;i++)
{
cout<<i<<endl;
}
output:
0
1
2
3
4
again,
for(int="" j="0;j<5;++j)
{
cout<<j<<endl;
}
Output" will="" be="" same.
my="" question="" is="" how="" the="" processing="" of="" code="" takes="" place?
++j="" &="" i++="" both="" are="" possessing="" same="" output,="" how?
<div="" class="signature">French is the language of love, for everything else there is c++ ...(anonymous)
|
|
|
|
|
For a built in type and not using the result of the expression ++n ; and n++; do the same thing. The only time there are any differences in behaviour are when the operators are used in more complicated expressions e.g.:
a = ++n;
and
a = n++;
For classes the situation is a bit different. It's up the class implementer to decide on the semantics of the operators - generally though you'd be asking for mockery to do something too off the wall and different from what built in types do.
Cheers,
Ash
|
|
|
|
|
I saw the same question from you in Q&A. Please, don't post the same question to multiple forums.
|
|
|
|
|
I agree with Sauro. If I'd seen the question here before I went to the effort of answering it in QA, I wouldn't have taken the trouble.
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
I have an CListCtrl object on an CFormView and on button click I want to rezise CListCtrl object ... here is my trial code :
void CTestView::OnButton1()
{
CRect Rect;
m_List1.GetWindowRect(Rect);
Rect.DeflateRect(Rect.left,Rect.top - 10,Rect.right,Rect.bottom);
m_List1.MoveWindow(Rect);
}
I want to short to 10 m_List1 less tall but keep bottom position ... but , when I clicked button , m_List1 disappear ... what I am doing wrong ?
I try in another way but with the same result :
void CTestView::OnButton1()
{
CRect Rect;
m_List1.GetWindowRect(Rect);
Rect.DeflateRect(Rect.left,Rect.top - 10,Rect.right,Rect.bottom);
m_List1.SetWindowPos(GetParent(),Rect.top - 10,Rect.left,Rect.Width(),Rect.Height() - 10,SWP_NOZORDER);
}
Can anybody help me ? Thank you.
|
|
|
|
|
I solve the problem , and here is my approach , in case that anybody needed :
I decrease tall with 10 of the list constrol :
void CTestView::OnButton1()
{
CRect Rect1,Rect2;
GetWindowRect(&Rect1);
m_List1.GetWindowRect(&Rect2);
int x = Rect2.left - Rect1.left - 2 * GetSystemMetrics(SM_CXBORDER);
int y = Rect2.top - Rect1.top - 2 * GetSystemMetrics(SM_CYBORDER);
m_List1.MoveWindow(x,y + 10,Rect2.Width(),Rect2.Height() - 10);
}
Here I increase tall with 10 of the list control :
void CTestView::OnButton2()
{
CRect Rect1,Rect2;
GetWindowRect(&Rect1);
m_List1.GetWindowRect(&Rect2);
int x = Rect2.left - Rect1.left - 2 * GetSystemMetrics(SM_CXBORDER);
int y = Rect2.top - Rect1.top - 2 * GetSystemMetrics(SM_CYBORDER);
m_List1.MoveWindow(x,y - 10,Rect2.Width(),Rect2.Height() + 10);
}
|
|
|
|
|
Hi guys,
As i am working on MDI application on VS2008, it had few modeless dialogs and tabbed views. During work, i found that if a modelless dialog is there and i invoked some context menu from the view, and now i clicked on the button of the modeless dialog, the dialog gets activated but the menu is not gone.
I guess i am clear what is the problem. as this is a normal problem and can be reproduced easily, no reelevent code snippet can be given.
Expecting some quick help..
HARSH
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning.
|
|
|
|
|
Hi, I have a dialogue-based MFC project. A user can input some inputs and I do the calculation behind the scene. After the calculation ( I might get 5 or 10 or 20 results), I want to display each result as CEdit control. Is it possible that I add those controls at runtime? Anyone has an example of how to do that?
Thanks
|
|
|
|
|
use CEdit::Create member function to create edit control at runtime.
|
|
|
|
|
It would be better to show the results in some other type of control like a list or multi-line edit/static control.
If using edit boxes created dynamically, there would be blank spaces on the dialog which may not look nice.
|
|
|
|
|
smengl wrote: I want to display each result as CEdit control. Is it possible that I add those
controls at runtime? Anyone has an example of how to do that?
CEdit *edit = new CEdit();
edit->Create();
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hi!
I need to convert UCHAR array to UINT array.
Example:
0 8 16 24 32 0 32
+------+------+------+------+ +------------+
INDATA | 0x11 | 0x22 | 0x33 | 0x44 | == CONVERT ==> | 0x11223344 | OUTDATA
+------+------+------+------+ +------------+
I have this two functions.
UINT uchar2uint(UCHAR * in)
{
return ((*in << 24) | (*(in + 1) << 16) | (*(in + 2) << 8) | *(in + 3));
}
void uchar2uinta(UCHAR * in, UINT * out, size_t outlen)
{
while(outlen--)
{
*out++ = uchar2uint(in);
in += 4;
}
}
int main(void)
{
int i;
UCHAR indata[8] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 };
UINT outdata[2];
uchar2uinta(indata, outdata, 2);
for(i = 0; i < 8; ++i)
printf("%#x ", indata[i]);
printf("\n");
for(i = 0; i < 2; ++i)
printf("%#x ", outdata[i]);
printf("\n");
return 0;
}
at the console displays the following text:
0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88
0x11223344 0x55667788
It's OK!
But, i can have a problems, when working in other system with different endianness (big-endian or little-endian)?
May be existed more correct way to convert?
Sorry for my poor English
Best regards, Alexander S.
|
|
|
|
|
What you have done will work in big- or little-endian systems. It is correct. There may be more *efficient* ways to do the conversion, depending on quirks of the hardware, compilers, etc.
Regards,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Many Thanks. I was primarily interested in portability of the code.
Regards,
Alexander S.
|
|
|
|
|
fasked wrote:
void uchar2uinta(UCHAR * in, UINT * out, size_t outlen)
{
while(outlen--)
{
*out++ = uchar2uint(in);
in += 4;
}
}
Try this instead, its simpler and will do the same you are looking for
void uchar2uinta(UCHAR * in, UINT * out, size_t outlen)
{
while(outlen--)
{
*out++ = *(UINT*)in;
in += 4;
}
}
HARSH
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning.
|
|
|
|