|
|
First thing I do in every C++ project is turn off precompiled headers.
And this is exactly the reason I do so.
I doubt precompiled headers are even relevant any more.
|
|
|
|
|
Agree on both counts, especially when one is ignorant about the "skipping code before the precompiled header" as I was.
With today's GB’s of memory and processing speed the time sawing is miniscule.
Maybe on large projects...
|
|
|
|
|
Hi all,
How to expand collapse a tree control all child items
with a single function.
|
|
|
|
|
CTreeCtrl::Expand[^] should do what you mean?
If you want to expand an item and expand all child items too, you'll have to loop through them.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
you can do it by calling the function CTreeCtrl::Expand function
like ctrl.Expand( hCurrentParent,TVE_EXPAND );
if you have multiple items at the most outer level , you need to call Exapand function for each of the items. you can use GetNextItem in CTreeCtrl for getting items. http://msdn.microsoft.com/en-US/library/a1azz3kt(v=VS.80).aspx[^]
If u can Dream... U can do it
|
|
|
|
|
Hi,
Refer for
BOOL Expand(
HTREEITEM hItem,
UINT nCode
);
Method in MSDN. You can achieve that.
Thanks,
Uday.
|
|
|
|
|
Two people giving the exact same answer as me, it must be true
modified 13-Sep-18 21:01pm.
|
|
|
|
|
Hello ,
i have the problem in run of this code can you view this code and give me the solution
code of produit.h:
#pragma once
#include <iostream>
#include <string.h>
using namespace std;
class produit
{
private:
int code;
char* edsignation;
static int totalprod;
public:
produit(const produit&);
produit&operator=(const produit&);
friend ostream& operator<<(ostream&,const produit&);
friend istream& operator>>(istream&, produit&);
produit(int=0,char*p="");
~produit(void);
};
code of produit.cpp :
#include "produit.h"
int produit::totalprod=0;
produit::produit(int x,char* d)
{
this->code=x;
this->edsignation=new char[strlen(d)+1];
strcpy(this->edsignation,d);
produit::totalprod++;
}
produit::produit(const produit&p){
this->code=p.code;
this->edsignation=new char[strlen(p.edsignation)+1];
strcpy(this->edsignation,p.edsignation);
}
produit& produit::operator=(const produit&p){
if(this!=&p){
this->code=p.code;
this->edsignation=new char[strlen(p.edsignation)+1];
strcpy(this->edsignation,p.edsignation);
}
return (*this);
}
produit::~produit(void)
{
delete [] edsignation;
}
ostream& operator<<(ostream& o,const produit&p){
o<<p.code<<" "<<p.edsignation<<" "<<produit::totalprod<<endl;
return o;
}
istream& operator>>(istream& i,produit&p){
if(p.edsignation) delete [] p.edsignation;
i>>p.code;
i>>p.edsignation;
return i;
}
Thanks.
|
|
|
|
|
Welcome to CodeProject.
Amine MAMA wrote: i have the problem
and which problem would that be? what are the symptoms? the compile-time or run-time error messages?
Please show your code inside PRE tags, they preserve formatting and improve readability; you can still edit your message.
|
|
|
|
|
the problem is on run time
|
|
|
|
|
1. WHAT problem? explain, describe, specify!
2. please use PRE tags, not CODE tags.
|
|
|
|
|
Hi, from the way your question is formulated, I'm not really sure what the problem is.
I've compiled the code myself though and it seems fine, so maybe you're after some help on how to use it?
I used the following code to try the functionality;
void main(void)
{
produit *prod1 = new produit(15,"Product1");
cout << *prod1;
Make a new product and ask the user to enter the code and designation
produit *prod2 = new produit();
cin >> *prod2;
cout << *prod2;
Make a new product and ask the user to enter the code and designation
produit *prod3 = new produit();
cin >> *prod3;
cout << *prod3;
}
The input/output was as follows;
15 Product1 1
86 Product2 <enter>
86 Product2 2
19 Product3<enter>
19 Product3 3
Which seems to be correct.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
thanks brother the problem is in allocation memory destructr
|
|
|
|
|
In your input function (istream& operator>>(istream& i,produit&p) , it is possible to write something into p.edsignation without it being allocated.
To solve this, you'd need to have a char* variable with sufficient length to hold any entered designation and then allocate your designation based on this.
e.g.
istream& operator>>(istream& i,produit&p)
{
if(p.edsignation)
delete [] p.edsignation;
i>>p.code;
char d[1024];
i>>d;
p->edsignation=new char[strlen(d)+1];
strcpy(p->edsignation,d);
return i;
}
modified 13-Sep-18 21:01pm.
|
|
|
|
|
|
As well as the problem that Thaddeus mentioned your assignment operator is going to leak memory. If you changed your code to use std::string instead of messing about with character arrays and manual memory management the problem would go away. If you used std::string you wouldn't need a copy constructor, assignment operator or destructor so it looks like a win all round to me.
And just about as I was going to hit send I noticed that your copy constructor and destructor doesn't update the static data member appropriately either.
Cheers,
Ash
PS: You might like to consider binning all the explicit this-> , there's no place in your code where you actually need it and it doesn't make your code any easier to read.
PPS: And the same goes for void as well.
|
|
|
|
|
Hi all,
If i have more then one hard disk in my system then how can i get its logical drive information in a format like Hard disk first then C:/,D:/...Then Hard disk2 E:/,F:/...
GetLogicalDrive() function retrieves all the Logical drives.
How can i do this???
Thanks in advance...
|
|
|
|
|
GetLogicalDrives returns an integer where each bit represents a drive letter which is either present (1) or not (0).
The least significant bit means A: and then each next bit is one letter up. So in order to check for the presence of drive C:, you'd test the 3rd bit:
if(GetLogicalDrives() & 4)
printf("Drive C: is present.");
The number 4 to AND with is represented as 00000000000000000000000000000100 in binary, so in effect you check if the 3rd bit is set.
You can use GetDriveType[^] to determine if a drive is a hard disk or something else, like a CD-ROM or network drive.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
I know of three ways:
1.
There are a number of Win32 functions for this in kernel32.dll; they include GetDriveType, GetVolumeInformation, GetDiskFreeSpaceEx, and maybe more.
2.
reading some keys in the registry. This is not recommended, and may trigger a UAC dialog, or fail, for non-admin accounts under Vista/Win7.
3.
the WMI classes provide a lot of information (e.g. Win32_DiskDrive, Win32_LogicalDiskToPartition, Win32_PhysicalMedia,
Win32_CDROMDrive). WMI works like a database, and it allows to query for other systems on the network.
|
|
|
|
|
learningvisualc wrote: How can i do this???
Are you wanting to know what logical drives belong to each physical drive? If so, see here. It's VB, but can easily be converted.
"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
|
|
|
|
|
Hi i am using vc++ 6.0 MSCOMM for serial communication i have to read data(4 bytes) and display from serial port.
ex: data format is
88 84 10 02 (4 bytes data from port)
C6 1E 10 02 (Received Data) but i have to display 88 84 but i am getting C6 and 1E.
my code is:
VARIANT data;
BSTR k;
static char dbuff[4];
int dcount=0;
CString data;
if(m_mscom.GetCommEvent()==2) // Receiving data from port
{
data=m_mscom.GetInput();
k=data.bstrVal;
dbuff[dcount] = char (k[0]);
dcount++;
if(dcount == 4)
{
dcount=0;
data.Format ("%02X%02X%02X%02X",(unsigned char)dbuff[0],(unsigned char)dbuff[1],(unsigned char)dbuff[2],(unsigned char)dbuff[3]);
}
}
please help what is the wrong in my code, thanks in advance,please give me one example how use BYTE to read the data
-- Modified Sunday, January 9, 2011 11:06 PM
|
|
|
|
|
The values 0x88 and 0x84 are the characters ê and ä from the extended ASCII table.
Seeing how these characters are changed but the lower ones (from the 128 character ASCII table) are not, it would appear these characters get translated somewhere to another code page; most likely either on the sender's side or in the data.Format call.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
You should not be using either CString or char for your data input, unless you can guarantee that it will be ASCII characters. Use a BYTE type to ensure that your data is presented as received and not converted on the way.
I must get a clever new signature for 2011.
|
|
|
|
|
I am having problems with populating an array with int numbers. Since I am a new programmer, I do not know why my VS 2008 is not completing the code block. In other words when I execute the program, a blank console screen opens. I then input a number and press enter. After I press enter the program stops in a suspended state. What I have discovered is that I have to input a \o for the program to know that it is the end of my input. I though thought that when I pressed enter, VS 2008 would automatically place this end of string designator.
Secondly, I have problems with index variable. When I loop one time or when I press enter after inputing a number, my index number advances to 8. My question is why the index does not advance to 2?
#include <stdio.h>
int const limit = 8;
int numbers[limit];
int main(void)
{
for(int index = 0; index < limit; index++)
{
scanf("%d", &numbers[limit]);
}
return 0;
}
|
|
|
|