|
you are looking for a rounding function
int round(double d)
{
return (int) (d + 0.5);
}
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
The FPU already does this for you.
inline int iround(double v){
int retval;
__asm fld qword ptr [v]
__asm fistp dword ptr [retval]
return retval;
}
inline unsigned int uround(double v){
unsigned retval;
__asm fld qword ptr [v]
__asm fistp dword ptr [retval]
return retval;
}
|
|
|
|
|
|
Hiii,,,
The following code doesn't take .
How to make it correct?
UINT64 ui_offset;
LONGLONG ll_array[ ui_offset];
Showing constraint error....!!!
Thank u
|
|
|
|
|
ui_offset has to be a constant.
Try this -
const UINT64 ui_offset = <value>;
LONGLONG ll_array[ui_offset];
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Hiiii....
I tried with
const UINT64 ui_offset = 1000000;
LONGLONG ll_array[ui_offset];
It works properly...
Thanking you......
|
|
|
|
|
What is woring in my following codes run time error is occuring for both code
int main()
{LPTSTR strResult;
LPTSTR strDefault=L"no";
DWORD d=255;
GetPrivateProfileString(L"data",L"Patchcab ",
strDefault,strResult,d,
L"D:\\TMP\\patchpolicy.ini");
printf("%s",strResult);
}
int main()
{
LPTSTR strResult=L"";
LPTSTR strDefault=L"no";
DWORD d=255;
GetPrivateProfileString(L"data",L"Patchcab ",strDefault,strResult
,d,L"D:\\TMP\\patchpolicy.ini");
printf("%s",strResult);
}
|
|
|
|
|
There is no memory allocated for the LpReturnedString parameter.
You're declaring it as LPTSTR strResult which is only a pointer.
You will need to do this -
TCHAR strResult[255];
DWORD d = 255;
Also change printf to _tprintf .
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
|
Hey, I think this is just a little mistake somewhere. I am new to using the STL algorithms, so i am totally botching it somehow.
My code looks like this:
typedef std::string Node;
typedef std::vector<Node> Cluster;
and down in the code i want to do this:
bool contains (const Cluster& cl, const Node& n)
{
Cluster::iterator it = find (cl.begin (), cl.end (), n);
(it == cl.end ()) ? return false : return true;
}
is that possible? or am i not allowed to do that? Thanks in advance!
|
|
|
|
|
Looks good except for the last return.
It should be return (it == cl.end ()) ? false : true;
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
«_Superman_» wrote: It should be return (it == cl.end ()) ? false : true;
return (it != cl.end());
FFY from me & Jijo.
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]
|
|
|
|
|
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Howdy'
I have some very bad code that should crash but I'm having difficulty figuring out why it does not crash (or even give out warnings); it works in VS2003 in release&debug and in VS2008 in debug, not in release.
class Info
{
public:
Info();
Info(std::wstring s1, std::wstring s2);
std::wstring m_string2;
};
struct myStruct
{
std::vector <Info*> m_JobInfoVector;
};
m_MyStruct = (myStruct*)malloc(sizeof (myStruct) );
ZeroMemory(m_MyStruct, sizeof(myStruct));
Info* p = new Info( std::wstring(_T("allo")) );
m_MyStruct->m_JobInfoVector.clear();
Question : What happens to the vector member when the ZeroMemory is called ? and why it does not crash in debug but it does in release ?
Thanks.
Max.
This signature was proudly tested on animals.
|
|
|
|
|
Why worry? The code is erronous, so the result of executing it is undefined. Just replace your malloc with new myStruct ...and don't, just don't ever write over a class with something like ZeroMemory - it just doesn't make sense. You have constructors to initialise structs and classes in C++.
But anyway - the error is in comparison of iterators (which clear does) - in VS2008, Debug mode iterators are different to Release mode iterators unless you specifically enable iterator debugging, which probably has something to do with it.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I know that, but I was wondering why it did not crash; anyway, the code has been fixed.
Thanks.
This signature was proudly tested on animals.
|
|
|
|
|
I think you are assuming that a struct in C++ works the same way as a struct in plain old C, but alas it doesn't... well not really anyway.
When you introduce non-primitive data types into structs in C++ they cease to be simple "data structures" and become basically the same as classes only their members default to public instead of private.
My guess is when you try to overwrite the object you are writing over the beginning of its virtual table which probably contains extra debug information in debug mode. In release mode you are then probably overwriting more important class data.
Remember, the sizeof operator is not designed to get the size of an object or its virtual table.
http://en.wikipedia.org/wiki/Virtual_method_table[^]
Chris Smith
|
|
|
|
|
Thanks, that's probably it; me think i will look at the memory a little closer.
This signature was proudly tested on animals.
|
|
|
|
|
hi,
My program creates files dynamically for that I gave location as desktop.
This code I wrote inside a fr loop, that means how many times this loop continues that many number of files will be created. For this situation how can I mention path that should able to generate any number of files.
sampath-padamatinti
|
|
|
|
|
What are you talking about? You already said that you're creating files on the desktop. What is your query?!
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
char directory[] = "my desktop";
for (int i=0;i<numFiles;++i)
{
char filePath[MAX_PATH];
sprintf(filePath, "%s\\%d.ext", directory, i);
} ?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
In addition to Stuart's reply,
There is an API to create file names, uniquely GetTempFileName
It will give a filename in specified directory with the prefix. It will automatically set a unique file name if you insist to do so. Read the MSDN for detailed information. An example is given here
|
|
|
|
|
It probably would have been better to reply to the OP rather than me
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: It probably would have been better to reply to the OP rather than me
Hello Madhu Nair, I agree with Stuart.
Sorry, couldn't resist.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Rajesh R Subramanian wrote: I agree with Stuart
Of course you do - everyone agrees with me...if they know what's good for them
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|