hi all
i spent a whole day to find out what the f**k is wrong with this code....
still got this error....plz anyone help!!!!
1 2 3 4
C:\>g++ huffman_driver.cpp -o huffman
In file included from huffman_driver.cpp:3:0:
huffman.h:33:31: error: expected identifier before numeric constant
huffman.h:33:31: error: expected ',' or '...' before numeric constant
huffman.h
#include <iostream> //for cout and cin
#include <string> //using string variable
#include <fstream> //working with input and output file
#include <vector>
usingnamespace std;
struct huff_node
{
unsignedlongint count; //cout the probibility of each character
signedshortint ch; //store the character
struct huff_node * left; // these are 3 pointers to structure for making huffman tree
struct huff_node * right;
struct huff_node * parent;
bool ignore; //true-> if we already handled this node
};
class huffman
{
public:
huffman (charconst *); // cunstructor of the class...get file name as input
void getLastError(void); // print out errorMessage
private:
bool error_occured; //true -> means some error ocurred !!!
string errorMessage; //store error message
constchar * inputFileName; //store input file name
constchar * outputFileName; //store output file name
ofstream myFileOut; //handle to input file
ifstream myFileIn; //handle to output file
vector<struct huff_node> vec (255); //array of our huffman structure
void readInputFile(void); //read each char from input file and count probility and store in array
};
First two things I see; no header guards on huffman.h (and you do include it twice) and you've got usingnamespace std in your header file, which is a bad idea and often leads to problems.
You're using exit without including the cstdlib. Your compiler shouldn't really let you get away with that.
Anyway, what's crippling your progress is this line.
vector<struct huff_node> vec (255); //array of our huffman structure
Lose the struct, and note that we declare an array using the square brackets, like this: vec[255]
However, making it an array of vectors makes little sense. Why not just try this:
vector<huff_node> vec;
If you didn't mean array, and you actually wanted a vector of size 255; this is the definition of a class. The vector is not being constructed here, so this is not the place to be calling constructors.
I suspect you didn't mean array, as later you try this: vec[i].count=0;
which suggests that you think vec should be a vector, not an array of vectors.
It compiles when I change
vector<struct huff_node> vec (255); //array of our huffman structure
to vector<huff_node> vec; //vector of our huffman structures
If I wanted to fiddle with the size of vec, I would do it in the class constructor (and i'd have to, if I didn't want a segfault, but those are easy to fix :) ).