|
This question was already posted in Q&A[^]; please post in one location only.
0100000101101110011001000111001011101001
|
|
|
|
|
|
Have you tried placing the counting code within either of those other loops to see if it counts what you expect? At first glance, I'd try:
while (0 < right)
{
temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
if (0 < arr[right])
PosCount++;
right--;
Sift(arr, left, right);
}
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
modified 13-Oct-11 9:39am.
|
|
|
|
|
Yes, the problem is that I don't understand the HeapSort good enough to reshape it whatever I want. That's why i need help..
|
|
|
|
|
Code aside, what part of the heap sort do you need help with: building the heap, or adding to the sorted array? I would forgo coding until I could do it all on paper first.
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Hi,
I am using WMI services to get Disk Information. But for a SD Card I am not getting correct physical size. It comes under logical e:\ drive in My Computer, for that (e:\) I am getting correct size but not for physical .
Please suggest.
|
|
|
|
|
Please give a bit more details. How are you querying the size? Show some code (don't forget the <pre>/</pre> tags) if possible. Tell us what you expect to get and what you do get.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
|
Hello people I have the following the code written in C++, converted from Vb.net to C++ from a program, the following code tells the user via message box if the program is running as an admin, see below
Object ^identity = WindowsIdentity::GetCurrent();
WindowsPrincipal ^principal = gcnew WindowsPrincipal(identity);
bool isElevated = principal->IsInRole(WindowsBuiltInRole::Administrator);
try
{
if (isElevated == true)
{
}
else
{
MessageBox::Show("WARNING: Program not running as administrator!", "Credential Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
}
}
catch (Exception ^ex)
{
MessageBox::Show("This program cannot run as performed because your system does not support admin rights, program now terminating from computer memory.", ".Net Framework Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
Environment::Exit(1);
}
When this block of code was executed with my program, I get the following error message (In double quotations):
"error C2664: 'System::Security::Principal::WindowsPrincipal::WindowsPrincipal(System::Security::Principal::WindowsIdentity ^)' : cannot convert parameter 1 from 'System::Object ^' to 'System::Security::Principal::WindowsIdentity ^'"
the remaining error messages are (In double quotations):
"1> No user-defined-conversion operator available, or
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast"
Could anyone point out something that I could edit that could make the compiler accept or work, any suggestions or personal solutions are appreciated .
|
|
|
|
|
|
|
Hi all,
I have an google imagery. And i want to implement a datum and projection for it.
how should i proceed?
Can any body please suggest something...
|
|
|
|
|
|
Hi, dear all,
Maybe my title make you confused, but I really don't know how to express it.
The project was created by other people before, inside the project there is a server called XXXX which inherite from COleServerDoc class. There are two containers that invoke the methods in the sever. Everything works fine.
Until now, before it only handle 4 types of materials, now it needs to handle 8 types of mateials, so I need to modify the server, otherwise it will cause array overflow. I modify the server and compile it, but when I run the container program, I still get the material overflow error, it totally didn't use the latest server I just compiled.
I check the container project and find it invode the server use the code: CreateDispatch(_T("XXXX.Document")), then I got to the Registry editor and find it was registered there before. So even I modify the server and recompile it, but the registered XXXX .Document is not updated, what should I do? how can I make the container project call my latest server?
Thank you very much!
|
|
|
|
|
Hello friends
I am writing in a Binary File Using FILE object.
And the structure that I am using while Writing is :
class A
{
int a;
int b;
};
While Reading Mine structure is :
class B
{
string name;
int a;
int b;
}
I am using fread like this way:
B* obj = new B();
fread(obj,sizeof(B)-sizeof(string),1,stream);
but not working,I m assuming that memory pointer obj is pointing at string name,so thats why i want to move obj pointer to int a,so it will read value of int a.
If ,i am wrong,please sugget me some other way. But there is restriction that i can change struture.
Thanks In Advance.
Regards
Yogesh
|
|
|
|
|
try
&obj->a
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Try ofstream[^] for serializing the objects in C++ way. Here[^] is an example.
Check this[^] site if you are interested to learn how to serialize in MFC.
|
|
|
|
|
I'd be inclined to load them individually.
I.e
B *obj = new B();
fread(&obj->a, sizeof(obj->a), 1, stream);
fread(&obj->b, sizeof(obj->b), 1, stream);
Please note also: the compiler may pad your structures where it sees fit, unless prevented via a compiler directive. I'd assume it also applied for classes, though do not know.
The implication is that if you declare a struct thusly:
struct simpleStruct{
char memberA;
long memberB;
}
You can often find that doing sizeof on each of the members then adding them together will give you a different result to sizeof theWholeStructure.
I.e, in my above example, it's quite possible that - sizeof(char) + sizeof(long) != sizeof(simpleStruct).
You may find that when you expect your structure to be 5 bytes as in the above example, that the compiler will pad it to 6 or 8 bytes. This means that when you do an fwrite using &simpleStuctInstance, you may in fact be adding 6 or 8 bytes to the file, although there are only 5 bytes of useful information. If you then do a fread using &simpleStructInstance, the extra bytes of padding will be magically of no consequence. However, if you fwrite the individual members out individually, then go onto fread the whole structure in one go, you'll be reading 6 or 8 bytes, discarding 1 or 3 of them and ending up with a struct that contains garbage.
This issue often arises when writing roll-your-own code for bitmap handling - failing to direct the compiler not to pad the structs results in all sorts of nasty behaviour.
|
|
|
|
|
That is really good advice concerning padding. It more often than not will cause huge grief and head aches when you ignore the effect of it.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
This is so wrong! If you go with this and release it into your commercial application then some developer some day is bound to change one of the classes but forget about the other one, at which time you system comes to a grinding halt. You should never use one class to save your data and a different one to restore it. Get your design right at the beginning and it will pay dividends in the future.
|
|
|
|
|
Hi,
I have a windows service which runs in XP, Vista and Win 7.
I am using WTSSendmessage() function to show a popup message at user desktop. But i need to display a popup message with different font size using the same WTSSendmessage() function.
Is there any way to accomplish this??
Thanks,
Nash
|
|
|
|
|
Not according to the documentation[^]. In general if you want a different font in message boxes then you need to create your own, either from scratch, or by subclassing an existing type, where that is possible.
|
|
|
|
|
I've put the topic in quotes, because I'm not asking for me. Instead I am referring to the various occasions I've seen where people advise inexperienced programmers to add
using namespace std; to their program. Personally I feel that this is not generally a good advice, for all of the reasons pointed out at http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.5[^].
But maybe the people offering this advice do have their reasons and take a different view? I'd like to know. What is your stance? Why do you think it is good to add a
using namespace statement, and when?
Or do you agree with me and generally advise against it? If so, can you offer any reasons not already offered at the site I linked above?
P.S.:
After reading the responses I've found there are indeed (IMHO) few strong arguments in favor of using using namespace std; . The two main arguments were:
1. Typing effort
2. Lack of readability, most notably (but not only) with the use of formatting in stream classes
Personally I don't think the typing effort should be considered a valid reason, unless there are absolutely no drawbacks to consider. Apart from that, both cases can be countered by various methods:
1. Use intelligent editors to minimize the typing effort
2. Use typedef to simplify complex (or just hard to type) expressions
3. Use a using declaration (e. g. using std::cout; ) rather than a using directive
In those rare cases where, locally, symbols from namespace std are being heavily used (e. g. an output function using lots of formatting), adding a using directive locally (i. e. within the scope of the function only) could be a reasonable compromise. Thanks to Stephen Hewitt for pointing that out.
modified 6-Oct-11 4:55am.
|
|
|
|
|
Well, if you have lots of code using funcs only form one namespace in a file, then you can reduce the amount of typing you have to do by stating 'using namespace' at the top of the file.
If you are not, and you are mixing lots of code from different namespaces, then you shouldnt, because you might have a clash somewhere, and either compiler errors or runtime errors.
==============================
Nothing to say.
|
|
|
|
|
I don't consider the typing to be a problem - good editors will reduce the extra typing to a minimum, and even in Notepad there's nothing preventing you from copy-pasting the extra std:: repeatedly. I do it all the time. (the copy-pasting, not using Notepad )
P.S.: You could also use typedef s to improve readability and reduce typing effort. This can be especially helpful for containers and iterators.
modified 3-Oct-11 4:23am.
|
|
|
|