|
can you just write a class to manipulate bits in an int, so it would contain 32 bool values instead of wasting that one number for 1 or a char for 8 values or double for 64 diff. values, wouldn't this be a better solution?
IM PROUD TO BE A GMAIL;
|
|
|
|
|
|
|
why don't you do it yourself ? is it so hard ?
look at this[^]...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Back in the old days of C when every byte of memory counted, we used to define a structure of bits so that it would be clearly referenced in code and only use a byte of memory. So, to declare six flags in a byte, you would define a struct like this:
typedef struct _tagBitFlags
{
unsigned char Flag1 : 1;
unsigned char Flag2 : 1;
unsigned char Flag3 : 1;
unsigned char Flag4 : 1;
unsigned char Flag5 : 1;
unsigned char Flag6 : 1;
unsigned char unused : 2;
} BitFlags;
Then to access the flags, you could write something like this:
if (BitFlags.Flag1)
printf("Flag1 is set");
else
printf("Flag1 is cleared");
Note that the value you can set a flag to must be in the bit range that the structure member can hold. This means that if, as in the above example, Flag1 is declared as one bit, it can only hold the values 0 and 1, whereas unused is declared as two bits and can be assigned the values 0, 1, 2, or 3.
Hope this doesn't date me too badly....
onwards and upwards...
|
|
|
|
|
Not at all. I am glad you typed it in. Saved me some work
|
|
|
|
|
Glad to be of service... and glad that I can remember back that far...
onwards and upwards...
|
|
|
|
|
Why don't you try the bitset from STL[^]?
You can easely do the following things:
typedef std::bitset<8> Flag8;
typedef std::bitset<11> Flag11;
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Imagine the following situation:
class A<br />
{<br />
public:<br />
A(int x, int y) {...}<br />
};<br />
<br />
int func1()<br />
{<br />
return ...;
}<br />
<br />
int func2(int arg)<br />
{<br />
return arg / 2;
}
You can not change the above. But you need to inherit from A and you want to pass func1() as the first argument and func2 of the first argument as the second argument to the constructor of A:
class B : public A<br />
{<br />
public:<br />
B():A(func1(), func2())<br />
{<br />
} <br />
};
What do you think is the best way to do this? A possible solution is:
class B : public A<br />
{<br />
protected:<br />
B(int x, int y):A(x, y))<br />
{<br />
} <br />
<br />
public:<br />
static B create()<br />
{<br />
int f1 = func1();<br />
return B(f1, func2(f1));<br />
}<br />
};
However, this would obstruct future inheritance from B.
|
|
|
|
|
How about the following?
<br />
class A2 : public A<br />
{<br />
protected:<br />
A2(int arg) : A(arg, func2(arg))<br />
{<br />
}<br />
};<br />
<br />
class B : public A2<br />
{<br />
public:<br />
B() : A2(func1())<br />
{<br />
}<br />
};<br />
Another possibility:
<br />
class B : public A<br />
{<br />
public:<br />
B(int x, int y) : A(x,y)<br />
{<br />
}<br />
<br />
B()<br />
{<br />
int f1 = func1();<br />
B aux(f1, func2(f1));<br />
*this = aux;<br />
}<br />
};<br />
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
The first one is nice indeed.
|
|
|
|
|
Hi CPians,
I would like to change programmatically the version information of a file (e.r. the ones you get when you open the properties dialog of a file in the explorer). This is for adding revision information automatically.
I know how to access this data (GetFileVersionInfo ,GetFileVersionInfoSize and similar) but how can I modify it ?
Thanks,
~RaGE();
|
|
|
|
|
Use RT_VERSION with this.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Thanks for the answer David, but this is only for Word documents, isn't it ? I was actually hoping to change the properties of any file (Word document, text file, ...).
~RaGE();
|
|
|
|
|
Rage wrote:
...but this is only for Word documents, isn't it ?
No, it works for others too.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
//header file
/////////////////////////////////////////////
node* next;
};
class cqueuetype
{
public:
cqueuetype();
void EnqueueRear(node* newNode);
void display();
bool isempty();
void makeEmpty();
void save();
void load();
void find();
void find1();
char infile();
void num_of_memo();
private:
node* rear;
node* front;
int counter;
};
//////////////////////////////////////////////
//Part of da cpp
//////////////////////////////////////////////
void cqueuetype::save()
{
node* saving=front;
ofstream outfile("c:\\queue.txt",ios::out);
if(!outfile)
{
cout<<"Can not find drive"<<endl;
}
="" else
="" {
="" outfile<<counter<<endl;
=""
="" while="" (saving="" !="NULL)
" outfile<<"title:"<<endl;
="" outfile<<"="" "<<saving-="">Title<<endl;;
outfile<<"date="" &="" time:"<<endl;
="" outfile<<"="" "<<saving-="">Date_Time<<endl;
outfile<<"memo:"<<endl;
="" outfile<<"="" "<<saving-="">Content<<endl;
outfile<<"....................................."<<endl;
="" saving="saving-">next;
}
outfile.close ();
}
}
And here is an example of da file it saved
2
TITLE:
Bad Day
Date & Time:
06/19/2005 04:19:27 PM
MEMO:
Today is da worst day in my life..
.....................................
TITLE:
Good Day
Date & Time:
06/20/2005 04:19:27 PM
MEMO:
Today is a Good day.
.....................................
Now this (2) is the number of memos in my file
but now i got a problem which is...as soon as close my programe and run it again , and ask da program to display da memos , it cant display it well , cause it cant read it from da file...
da other problem is , if i added a new entry before i load da file , all da old enteries will be deleted... it will over write on it...
So... i need to know what shall i do , and what is da prober load function i can use , where i have 3 string , in dat node i load....
My regards ,
Bahy
|
|
|
|
|
ana_bahy wrote:
and ask da program to display da memos , it cant display it well , cause it cant read it from da file...
That's normal because when you open the file, its contents are destroyed. Try to use that instead:
ofstream outfile("c:\\queue.txt",ios::out | ios::app);<br />
ana_bahy wrote:
da other problem is , if i added a new entry before i load da file , all da old enteries will be deleted... it will over write on it...
We cannot guess what's happening during the load if you don't post the code.
And please, use the formating tags to make your code look better (it is just above the emoticons, use the 'code' or 'pre' tag).
|
|
|
|
|
Thank you soo much for ur fast reply , i really appriciate that
Here is my load code
//////////////////////////////////////////////////////////
char cqueuetype::infile()<br />
{<br />
char Title[30];<br />
char Content[100];<br />
char Date_Time[36];<br />
<br />
ifstream infile("c:\\queue.txt",ios::in);<br />
cout<<"\n\n\n\t Data are be saved now\n\n\n"<<endl;<br />
infile >> counter;<br />
for (int b=0;b<counter;b++) <br />
{ <br />
<br />
infile.ignore(7);<br />
infile.get(Title,30,'#');<br />
infile.ignore(13);<br />
infile.get(Date_Time,36,'#');<br />
infile.ignore(6);<br />
infile.get(Content,100,'#');<br />
node* temp;<br />
temp=new node;<br />
<br />
temp->Title=Title;<br />
temp->Date_Time=Date_Time;<br />
temp->Content=Content;<br />
temp->next= NULL; <br />
if (front==NULL)<br />
{<br />
rear=temp;<br />
front=temp;<br />
temp->next=NULL;<br />
}<br />
else<br />
{<br />
temp->next=front;<br />
front->next=temp;<br />
front=temp; <br />
}<br />
} <br />
infile.close();<br />
return 0;<br />
<br />
}
/////////////////////////////////////////////////////////////
My regards,
Bahy
|
|
|
|
|
Remarks:
for (int b=0;b<counter;b++)
|
|
|
|
|
for (int b=0;b<counter;b++)
|
|
|
|
|
Ok ok ok !! Stop it Don't overflow the forum by trying to format it
for (int b=0;b<counter;b++)
|
|
|
|
|
The only way to print a < symbol is to use the tag next to the 'code' tag. But ok, I understood what it was... And when you say that it cannot load the data, what is exactly the problem ? (Try to be as much precise as possible).
|
|
|
|
|
Do u have A personal email , to send u da file?
|
|
|
|
|
Other peope here are also able to help you. I don't know if I can solve your problem so it is better to post everything on the forum. And I don't need your source files because I don't have the time to run a project for that.
Better try to understand your problem and then give here a good description of what is happening. Also, a tool that could help you a lot is the debugger (press F9 to set a breakpoint somewhere in your code and press F5 to start the debugger). You will be able to watch the different variables and see what's happening.
|
|
|
|
|
Its ok... Thanks anywayz for your help... :->
My regards,
Bahy
|
|
|
|