|
Linda10 wrote:
ru blind?
Nope, your pic is missing.....
Nick Parker
You see the Standards change. - Fellow co-worker
|
|
|
|
|
Hey linda, dude, or whatever, that is most certainly NOT you, unless Sylvia Saint, the porn star has suddenly taken up programming!!!
Cute pic though!
¡El diablo está en mis pantalones! ¡Mire, mire!
|
|
|
|
|
|
Duh....,lucky guess !!
¡El diablo está en mis pantalones! ¡Mire, mire!
|
|
|
|
|
Well that was kind of a knee jerk reaction...on second thought you have a n excellent point!!!
¡El diablo está en mis pantalones! ¡Mire, mire!
|
|
|
|
|
http://www.ltpb.8m.com/Links.htm#Free[^]
-Steven
By reading this message you are held fully responsible for any of the mispelln's or grammer, issues, found on, codeproject.com.
For those who were wondering, actual (Linux) Penguins were harmed in creating this message.
|
|
|
|
|
|
Keep It Simple Stupid??
If you kiss anyone you may want to kiss bob (lonely mascot of the site).
-Steven
By reading this message you are held fully responsible for any of the mispelln's or grammer, issues, found on, codeproject.com.
For those who were wondering, actual (Linux) Penguins were harmed in creating this message.
|
|
|
|
|
I want KISS too
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
How do I scroll up/down a CRichEditCtrl, so that the bottom of it shows the last line of the multi-line text contents? I'm currently using LineScroll(15), but that leaves a blank line or two at the bottom of the control.
Thanks!
|
|
|
|
|
I use this to scroll it automaticaly to the last line.
int nn = edView->GetScrollLimit(SB_VERT);
if (nn) {
edView->SetScrollPos(SB_VERT,nn);
edView->LineScroll(1);
}
where edView is a CRichEditCtrl.
It does the trick if the dimensions of the font does not change.
-----
We are what we repeatedly do. Excellence, then, is not an act, but a habit.
|
|
|
|
|
I want to output vector<bool> to file,how can i do it?(using std and so on)
can anyone help me?
|
|
|
|
|
Wouldn't the most obvious approach work?
out_stream.write(&vec[0], vec.size() * sizeof(vec.value_type));
|
|
|
|
|
#include <fstream>
#include <vector>
using namespace std;
void main()
{
const int Max=20;bool b;
vector<bool> vec[Max];
for(int i=0;i
|
|
|
|
|
TheWay wrote:
vector vec[Max];
Note: OP intended for it to be vector <bool>
Ehhh, OK. You create an array of 20 vectors, all initially empty. Then you fill each of them with a random number of elements (0-9 to be precise), with the value of the outer loops (i&2) != 0.
There are two issues at hand here:
1) the bool specialization for vector is by many considered an error of the C++ standard (and will probably be removed).
2) Your code makes no sense (to me).
If you really want to output 20 ["something" repeated a randomized number of times], what about just
char mem[10];
for (int i=0; i < 20; ++i) {
const size_t n = rand()%10;
if (n) {
memset(mem, (i&2)!=0, n);
out.write(mem, n);
}
}
OK, this code doesn't call rand() for every inner loop like yours did. I don't know if you depended on some property of your C runtime library's rand() function. Feel free to change it to an inner loop with a stochastic loop-termination condition if you really want to confuse any potential readers.
|
|
|
|
|
what I want to do is that outputing a char's Huffman code from HuffmanTree ,which contains a vecter<bool> node,to binary files.
(I am sorry my english is not very good,so i just list my code here--two class
I am very appreciate for your help.)
// HuffmanTree.h
#ifndef HUFFMANTREE_H
#define HUFFMANTREE_H
#include <math.h>
#include "binary.h"
#include <iostream>
#include <fstream>
#include <string>
#include "MinHeap.h"
#include "CharSetNode.h"
using namespace std;
void charToString(const char& c,string& s)
{
s="00000000";char x;
x=c&0x01; if(x) s[7]='1';
x=c&0x02; if(x) s[6]='1';
x=c&0x04; if(x) s[5]='1';
x=c&0x08; if(x) s[4]='1';
x=c&0x10; if(x) s[3]='1';
x=c&0x20; if(x) s[2]='1';
x=c&0x40; if(x) s[1]='1';
x=c&0x80; if(x) s[0]='1';
}
template<class T>
class HuffmanTree
{
public:
HuffmanTree(int =128);
~HuffmanTree(){Destroy();delete []CSF;}
void Init(string str="Ch19.txt");
void InitFromFile(const string& s);
void OutputCharSet(ostream& out);
void OutputCodeFile(ostream& out);
void OutputHeap(ostream& out);
void OutputHuffTree(ostream& out);
bool Encoding();
bool Decoding(string str);
void DeleteVisit(CharSetNode<T> *t);
void Destroy();
private:
void CalCharFreq();
void CreateHuffTree();
void ZeroOneVisit(CharSetNode<T> *t,vector<bool> v);
void CreateZeroOne();
CharSetNode<T> *Root;
CharSetNode<T> *CSF;
int Max;
bool CreateOneZero;
string strFile;
};
template <class T>
HuffmanTree<T>::HuffmanTree(int CharSetMaxNum):Max(CharSetMaxNum)
{
Root=0;CreateOneZero=false;
CSF=new CharSetNode<T>[Max];
int i=0;
for(;i<0x20;++i) CSF[i].v=ASCII_uPrint[i];
for(;i<0x7F;++i) CSF[i].v=(char)i;
CSF[i].v=ASCII_uPrint[0x20];
for(i=0;i<Max;++i) CSF[i].ascii=i;
Init();
}
template <class T>
void HuffmanTree<T>::Init(string str)
{
strFile=str;
CalCharFreq();
CreateHuffTree();
CreateZeroOne();
}
template <class T>
void HuffmanTree<T>::Destroy()
{
}
template <class T>
void HuffmanTree<T>::DeleteVisit(CharSetNode<T> *t)
{
CharSetNode<T> *last=t;
while(t)
{
if(t->l) DeleteVisit(t->l);
if(t->r) DeleteVisit(t->r);
delete last;
}
}
template <class T>
void HuffmanTree<T>::InitFromFile(const string& s)
{
for(int i=0;i<Max;++i)
CSF[i].InitFromFile(s);
// if(Root) Destroy();
CreateHuffTree();
}
template <class T>
void HuffmanTree<T>::OutputCodeFile(ostream& out)
{
for(int i=0;i<Max;++i)
CSF[i].OutputCodeFile(out);
}
template <class T>
void HuffmanTree<T>::OutputCharSet(ostream& out)
{
for(int i=0;i<Max;++i)
CSF[i].Output(out);
}
template <class T>
void HuffmanTree<T>::OutputHuffTree(ostream& out)
{
out<<endl<<"生成的树(层次遍历)是:"<<endl;
LinkedQueue<CharSetNode<T>*> Q;
CharSetNode<T> *t=Root;
while(t)
{
t->OutputTree(out);
if (t->l) Q.Add(t->l);
if (t->r) Q.Add(t->r);
try {Q.Delete(t);}
catch (OutOfBounds) {return;}
}
}
template <class T>
void HuffmanTree<T>::OutputHeap(ostream& out)
{
out<<endl<<"生成的堆(层次遍历)是:"<<endl;
LinkedQueue<CharSetNode<T>*> Q;
CharSetNode<T> *t=Root;
while(t)
{
// t->OutputTree(out);
t->OutputHeap(out);
if (t->l) Q.Add(t->l);
if (t->r) Q.Add(t->r);
try {Q.Delete(t);}
catch (OutOfBounds) {return;}
}
}
template <class T>
void HuffmanTree<T>::CalCharFreq()
{
ifstream fin;
fin.open(strFile.c_str());
if(fin.fail()){cerr<<"can't input file!!\n";return;}
char c;int n;int fileSize=0;
while(true)
{
fin.get(c);
if(fin.eof()) break;
n=c;
CSF[n].occur++;
fileSize++;
}
fin.close();
}
template <class T>
void HuffmanTree<T>::CreateHuffTree()
{
MinHeap<CharSetNode<T> > H(1);
CharSetNode<T> *tmp=new CharSetNode<T>[Max+1];
for(int i=0;i<Max;++i)
tmp[i+1]=CSF[i];
H.Initialize(tmp,Max,Max);
CharSetNode<T> *x=NULL,*y=NULL,*w=new CharSetNode<T>;
for(i =1;i <Max;i++)
{
x=new CharSetNode<T>;
y=new CharSetNode<T>;
x->l=x->r=y->l=y->r=0;
H.DeleteMin(*x);
H.DeleteMin(*y);
w->v="empty";
w->ascii=-1;
w->occur=x->occur+y->occur;
w->lev=(x->lev>y->lev) ? x->lev+1 : y->lev+1;
if(x->occur>y->occur)
{ w->l=x;w->r=y;}
else if(x->occur<y->occur)
{ w->r=x;w->l=y;}
else
if(x->lev<y->lev)
{ w->l=x;w->r=y;}
else
{ w->r=x;w->l=y;}
H.Insert(*w);
}
H.DeleteMin(*w);
H.Deactivate();
delete []tmp;
Root=w;
// ofstream fout("fff.txt");
// OutputHuffTree(fout);
}
template <class T>
void HuffmanTree<T>::ZeroOneVisit(CharSetNode<T> *t,vector<bool> v)
{
if(t)
{
t->ZeroOne=v;
if(t->ascii!=-1) CSF[t->ascii].ZeroOne=v;
v.push_back(0);
ZeroOneVisit(t->l,v);
v.pop_back();
v.push_back(1);
ZeroOneVisit(t->r,v);
v.pop_back();
}
}
template <class T>
void HuffmanTree<T>::CreateZeroOne()
{
if(!Root){cout<<"请先初始化!!"<<endl;return;}
else
{
vector<bool> v;
ZeroOneVisit(Root,v);
CreateOneZero=true;
}
}
template <class T>
bool HuffmanTree<T>::Encoding()
{
if(!CreateOneZero)
{cout<<"相应的哈夫曼码树还没生成!!"<<endl;return false;}
else
{
ifstream fin;
fin.open(strFile.c_str());
if(!fin.is_open())
{
cout<<"file can't open!!"<<endl;
return false;
}
string strOut="Nai_"+strFile;
ofstream fout(strOut.c_str(),ios::binary);
if(!fout.is_open())
{
cout<<"file can't open!!"<<endl;
fin.close();return false;
}
char c,out;long chSize=0;
string s="";
fout.seekp(16);
while(true)
{
fin.get(c);
if(fin.eof()) break;
for(int i=0;i<CSF[(int)c].ZeroOne.size();++i)
{
s+=(CSF[(int)c].ZeroOne[i])?'1':'0';
++chSize;
if(chSize%(8*sizeof(char))==0)
{
out=0;
for(int i=0;i<8*sizeof(char);++i)
if(s[i]=='1') out+=pow(2,8*sizeof(char)-i-1);
fout<<out;
s="";
}
}
}
if(chSize%(8*sizeof(char))!=0)
{
out<<=8*sizeof(char)-chSize%(8*sizeof(char));
fout<<out;
}
fout.seekp(0);
fout<<chSize;
fin.close();fout.close();
}
return true;
}
template <class T>
bool HuffmanTree<T>::Decoding(string str)
{
if(!Root) return false;
if(str==""){ cout<<"错误文件名!!"<<endl;return false;}
if(!CreateOneZero)
{cout<<"相应的哈夫曼码树还没生成!!"<<endl;return false;}
ifstream fin(str.c_str(),ios::binary);
if(!fin.is_open())
{
cout<<"file can't open!!"<<endl;
return false;
}
string out="Un_"+str;
ofstream fout(out.c_str());
if(!fout.is_open())
{
cout<<"file can't open!!"<<endl;
fin.close();return false;
}
char c;string s;long chSize;
CharSetNode<T> *t,*last;
last=t=Root;
fin>>chSize;
fin.seekg(16);
fin.get(c);
if(fin.eof()) return true;
while(true)
{
charToString(c,s);
for(int i=0;i<8;++i)
{
if(s[i]=='1')
{
t=t->r;
if(!t->r)
{fout<<(char)t->ascii;t=Root;}
}
else
{
t=t->l;
if(!t->l)
{fout<<(char)t->ascii;t=Root;}
}
if(--chSize<=0) return true;
}
fin.get(c);
if(fin.eof()) return true;
}
fin.close();fout.close();
return true;
}
#endif
///
//CharSetNode.h
#ifndef CharSetNode_H
#define CharSetNode_H
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const string ASCII_uPrint[0x21]={/*Ox00-0x19*/
"NULL","SOH","STX","ETX","EOT","ENQ","ACK","BEL",
"BS","HT","LF","VT","FF","CR","SO","SI","DLE","DC1",
"DC2","DC3","DC4","NAK","SYN","ETB","CAN","EM",
"SUB","ESC","FS","GS","RS", "US",/*0x7F*/"DEL"};
template<class T> class HuffmanTree;
template<class T> class BianryTree;
template<class T>
class CharSetNode
{
friend HuffmanTree<T>;
friend BianryTree<T>;
public:
CharSetNode(){occur=0;l=r=0;lev=0;}
void InitFromFile(const string& s);
operator T () const {return occur;}
void Output(ostream& out) const;
void OutputCodeFile(ostream& out) const;
void OutputHeap(ostream& out) const;
void OutputTree(ostream& out) const;
void OutputZeroOne(ostream& out) const;
CharSetNode<T>& operator= (const CharSetNode& x);
private:
vector<bool> ZeroOne;
string v;
long occur;
short int ascii;
CharSetNode<T> *l,*r;
unsigned short lev;
};
template<class T>
CharSetNode<T>& CharSetNode<T>::operator= (const CharSetNode& x)
{
if(this!=&x)
{
v=x.v;lev=x.lev;
occur=x.occur;
ZeroOne=x.ZeroOne;
ascii=x.ascii;
l=x.l;r=x.r;
}
return *this;
}
template<class T>
void CharSetNode<T>::Output(ostream& out) const
{
if(v!="empty")
{
out<<v<<"\t";
out//<<ascii<<"\t"
<<occur<<"\t";
for(int i=0;i<ZeroOne.size();++i)
out<<ZeroOne[i];
out<<endl;
}
}
template<class T>
void CharSetNode<T>::OutputCodeFile(ostream& out) const
{
if(v!="empty")
{
out<<ascii<<"\t"<<occur<<"\t";
for(int i=0;i<ZeroOne.size();++i)
out<<ZeroOne[i];
out<<endl;
}
}
template<class T>
void CharSetNode<T>::InitFromFile(const string& s)
{
ifstream in(s.c_str());
if(in.fail()){cout<<"can't open file!!"<<endl;return;}
in>>ascii>>occur;
string str;bool b;
in>>str;
for(int i=0;i<str.size();++i)
{
b=(str[i]=='1')?1 ;
ZeroOne.push_back(b);
}
}
template<class T>
void CharSetNode<T>::OutputZeroOne(ostream& out) const
{
out<<v<<"\t:";
for(int i=0;i<ZeroOne.size();++i)
out<<ZeroOne[i];
out<<endl;
}
template<class T>
void CharSetNode<T>::OutputHeap(ostream& out) const
{
if(v!="empty") out<<v<<"出现:"<<occur;
else out<<"这是非叶结点 出现:"<<occur;
// for(int i=0;i<ZeroOne.size();++i)
// out<<ZeroOne[i];
out<<endl;
}
template<class T>
void CharSetNode<T>::OutputTree(ostream& out) const
{
if(v!="empty") out<<v<<"\t权值:"<<occur<<"\t";
else out<<"非叶结点 权值:"<<occur<<"\t";
for(int i=0;i<ZeroOne.size();++i)
out<<ZeroOne[i];
out<<endl;
/**/
}
template<class T>
ostream& operator<< (ostream& out,const CharSetNode<T>& x)
{
x.Output(out);
// x.OutputHeap(out);
// x.OutputTree(out);
// x.OutputZeroOne(out);
return out;
}
#endif
my question:
how can i change the ascii file to huffman code file which is binary?
If you are happy to help,you can e-main to me :sware_master_nai@163.com (I live in china)
|
|
|
|
|
|
Hi,
I am currently making a custom dialog control, and I'm adding some keyboard support. I'm wondering if anyone knows how I can recieve messages for key presses like up, down, left, right and tab without my control loosing the keyboard focus till I want it to.
Any help is much appreciated...
With time we live, with money we spend!
Joel Holdsworth.
|
|
|
|
|
Look at the WM_GETDLGCODE message. The dialog sends this to your control to query which keys you are interested in.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
>>Problem with losing focus
Oh, I thought you were referencing a normal work day...
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
I am doing a map editor for a game.
The level is 1024x1024 tiles big, with each tile being 16 pixels with default zoom.
I am drawing the tiles by checking if each 64x64 tile portion of the map is visible(CDC::RectVisible) and if it is, I go through all the tiles and paint the ones that are visible(CDC::RectVisible again).
I BitBlt the tiles from a CDC that contains them all.
Then I just use lines to draw a grid over the 64x64 tile square.
Tilesets are generated at start for all zooms, so they're already avilable when drawing.
Now this works OK(45ms drawing. Hey, I use 350mhz ) with 100% zoom,
but with 25% zoom it is quite slow(110ms, altough it feels even slower)
Both are for totally empty map btw!
250ms for full map with 100%
1060ms for full map with 25%
What could I optimize here? Or am I doing something majorly wrong with drawing it?
|
|
|
|
|
Make sure both your tiles and your off-screen bitmap is in video memory. If not, blitting will be slow.
The easiest way to ensure this I believe is to CreateCompatibleBitmap(GetDC(0), ...);
|
|
|
|
|
hello
if "i","j" are double
i=1.2345678
j=2.345678
cout<
|
|
|
|
|
printf("%.2f\n", i*j); - I believe that should do the trick!
With time we live, with money we spend!
Joel Holdsworth.
|
|
|
|
|
If I prefer use cout rather than printf
how can I do???
THX!!!
|
|
|
|
|