|
could you explain a bit more ?
i don't understand why you're talking about a class for integers.
don't you want to use signed /unsigned int /short /long ??
TOXCCT >>> GEII power
|
|
|
|
|
No I mean decimal numbers, like 1.234
float and double are no good at representing certain values (e.g. 0.1)
I need a class that can accruately represent decimal numbers
|
|
|
|
|
Instead of float (4 bytes), use double (8 bytes) or long double (10 bytes) if you need even more precision
|
|
|
|
|
did you have a look at float.h ? you certainly didn't.
you will find many "tools" to manage non real values like infinites, resolution loose, and so...
and about your 0.1, i don't understand why float is not good...
TOXCCT >>> GEII power
|
|
|
|
|
toxcct wrote:
and about your 0.1, i don't understand why float is not good...
float and double are nice containers for floating point numbers, but they aren't accurate, they can't accurately describe 2 1/3 for example.
While double is ok for most apps, it would be a poor choice for eg. insurance companies where the roundings in the complex actuarial formulas would mean filtering away billions of dollars.
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
|
Technically, decimal means base-10 (deca is Greek for ten). So, rather than using a float type, are you wanting to use an int type?
If you simply need more precision, you might try the DECIMAL type. However, I suspect you are not having precision problems. Most beginners assume you can compare floating-point numbers just like you can non floating-point numbers. For example, this would never produce the desired result:
float a = 0.1;
if (a == 0.1)
... because a is stored internally as 0.0999999999, give or take a few 9s.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I am trying to read the entire content of a text file with the following code:
File.seekg(0, ios::end);<br />
<br />
long lFileSize = File.tellg();<br />
<br />
szFileBuffer = new char[lFileSize + 1];<br />
<br />
if ( szFileBuffer == NULL )<br />
{<br />
MessageBox(NULL, "There is not enough memory to run this application",<br />
NULL, MB_ICONERROR | MB_OK);<br />
<br />
return 1;<br />
}<br />
<br />
File.seekg(0, ios::beg);<br />
<br />
File.get(szFileBuffer, lFileSize + 1, EOF);<br />
<br />
File.close();
The actual filesize is 715KB but the program is only reading 540KB...tellg gives the correct filesize yet get seems to only be getting 540KB...are there any workarounds for this...in general, are there buffer size limitations as far as istream::get is concerned?
|
|
|
|
|
Hi,
Think having some prob with EOF state. Have a look @ msdn for basic_istream::seekg.
This may help you
Sujan
|
|
|
|
|
Hi
For reading entire file content, try use block (not stream) i/o.
<br />
FILE *pFile = fopen(fname, fmode);
fseek(pFile, 0, SEEK_END);<br />
long len = ftell(pFile);<br />
char *data = new char[len];<br />
fseek(pFile, 0, SEEK_SET);<br />
long rest = len;<br />
long tpos = 0;<br />
while(rest)<br />
{<br />
long rd = fread(data+tpos, 1, rest, pFile);<br />
if (!rd)<br />
{<br />
}<br />
else<br />
{<br />
rest -= rd;<br />
tpos += rd;<br />
}<br />
fclose(pFile)
|
|
|
|
|
How are you opening the file? If the file is opened as "text" then any EOF character encountered before the last one will cause the get() call to end prematurely.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thanks for the replies...yes the file is being opened as text...there shouldn't be a premature EOF character in there...but in general, what are my options while keeping this file open as text?
|
|
|
|
|
Dear friends,
I am giving "&" symbol to menu items, but at runtime, the Menu item is not underlined. Its only when i press "Alt" key it becomes underlined. I want the "short Key" character to be visible at runtime, just like Visual C++ 6.0 IDE or MS Office. How can i do so ?
Imtiaz
|
|
|
|
|
This is by settings in XP - Screen properties/Appearance - then Effects button and uncheck Hide underlined...
|
|
|
|
|
Yes, but how Visual Studio and MS-WORD are showing underline symbol when the option is either selected or not selected ??
Imtiaz
|
|
|
|
|
Because they have their menu ownerdraw and decided for whatever reason to ignore this system setting.
The setting for the system can be retrieved by
function SystemParametersInfo , using flag SPI_GETKEYBOARDCUES .
You can change the setting for the system by using SPI_SETKEYBOARDCUES flag with the mentioned function.
Hope that helps.
|
|
|
|
|
Hi all,
can anybody gimme the program with code to create a anolog clock.
thanks in advance.
Mr.Dayala
ThomasKennedyBose
|
|
|
|
|
search for analog clock in c++ section at http://www.planetsourcecode.com
-----------------------------
"I Think It Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
hi alok,
thanks for quick reply..I found it in planetsource bit it is on general C++.I want it in VC++..can help me out?? my problem is with time, otherwise I can manage by wriitng myself.
thanks in advance.
ThomasKennedyBose
|
|
|
|
|
could you eloborate you problem or mail me at thatsalok@gmail.com
-----------------------------
"I Think It Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
Mr Bose Dayala wrote:
can anybody gimme the program with code to create a anolog clock.
Probably, but nobody will. Why don't you write it yourself and if you run into any problems, ask a question about how to do a particular thing. You're much more likely to get a useful response that way.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I found one some months ago here on CP. have you looked here in the articles?
besides I don't think it should be so dificult to make.
think of what parts a clock consists (circle, lines, pointers,...) All of them are static accept the pointers, the base is static (center of the circle) while the point moves, it moves (for the seconds) 360/60 of the circle every second.
The only thing you need to do is to redraw this pointer every second on the right place.
Just know your geometry.;)
hope this helps...
[EDIT]
Oh by the way, I did analog meters for a car once, which worked perfectly, the one thing you may want to consider is buffering to reduce flicker. I did it as described above, but I don't have the code anymore
[/EDIT]
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
I am calling Form2 from Form1, and depending on the input in Form2, I want to enable/disable buttons in Form1 when I exit. However, because I need to call Form2 header before I define class Form1, Form1 is not defined when the compiler sees my call to it. If I therefore call Form1 header in Form2 header, then the compiler will see my call to Form2 before Form2 is defined!!.
Basically therefore, I wanna be able to call each form from each form, but have to define and make the call in one first.
This seems to me a very obvious thing to want to do, but I can't figure out myself how to do it, as you can't declare an extern class, or see any examples on the net of how to do it in Visual C++.net.
Any help appreciated, as is a real stumbling block for me.
UltimateNewbie
|
|
|
|
|
Hi,
In any case one form will be the parent of the other form. So in the 2nd form use the GetParent() function to get the pointer cast it to the parent parentclass, set the parent's values using the currently got value
Have a look @ the following code,
CParentDlg *pParent = (CParentDlg *) GetParent();
pParent->m_iNewValue = m_iGotValue;
Hope this will help you.
Sujan
|
|
|
|
|
Your question is a little confusing, but I think you need to a forward declaration of one of your classes.
class Form1; in your Form2.h
or
class Form2; in your Form1.h
A lot depends on how the classes are referencing each other.
Michael
CP Blog [^]
|
|
|
|