im new with C++ . i was in java but now im learning C++ and i am not very good at it . i am making a program about spam and ham emails . i have all the files in the same directory . i created Ergasia1.cpp , Ergasia1.h , Feature.cpp , Feature.h
but when i compile Ergasia1.cpp i got errors like :
1. " In file included from Ergasia1.cpp "
2. " Ergasia1.h [Warning] extra tokens at end of #endif directive "
3. "Feature.h [Warning] extra tokens at end of #endif directive " (after this error there are several errors like this " [Linker error] undefined reference to `Feature::getDescription()' "
4. " Feature.h ld returned 1 exit status "
and when i compile Feature.cpp i got errors like :
1. " In file included from Feature.cpp "
2. " [Linker error] undefined reference to `WinMain@16' "
3. " Feature.h ld returned 1 exit status "
Ergasia1.cpp
#include "Ergasia1.h"
#include "Feature.h"
using namespace std;
Ergasia1::Ergasia1()
{
#ifdef DEVEL
tst= "../../";
#else
tst= "./";
#endif
bool AllOK= FillvsKeys();
if (AllOK) {
GetFiles(LING);
GetFiles(SPAM);
ShowData();
}
else
cout << "Incorrect Installation!" << endl;
}
const void Ergasia1::AnalyzeFile(const string fn) {
string fname= fn.substr(tst.length());
size_t pos= fname.find_first_of("/");
string kind= "";
if (pos != string::npos)
kind= fname.substr(0, pos);
int KeywordsFound= 0;
ifstream ifs(fn.c_str());
if (ifs.is_open()) {
n++;
vector<Feature> vf;
while (! ifs.eof()) {
string line;
getline(ifs, line);
for (unsigned int i= 0; i < vsKeys.size(); i++) {
string key= vsKeys[i];
if (line.find(key) != string::npos) {
bool found= false;
for (unsigned int j= 0; j < vf.size(); j++)
if (vf[j].getDescription().compare(key) == 0) {
int x= vf[j].getFrequency();
vf[j].setFrequency(++x);
found= true;
break;
}
if (! found) {
Feature *f= new Feature(i, 1, key);
vf.push_back(*f);
KeywordsFound++;
}
}
}
}
ifs.close();
ostringstream osst;
osst << "<message file=\"" << fname <<"\" category=\"" << kind << "\" features=\"" << KeywordsFound << "\">";
vsStream.push_back(osst.str());
osst.flush();
for (unsigned int i= 0; i < vf.size(); i++) {
ostringstream ossb;
ossb << "<feature id=\"" << vf[i].getId() << "\" freq=\"" << vf[i].getFrequency() << "\"> " << vf[i].getDescription() << " </feature>";
vsStream.push_back(ossb.str());
ossb.flush();
}
ostringstream osse;
osse << "</message>";
osse.flush();
}
}
const void Ergasia1::GetFiles(const string Kind) {
string s= tst + Kind + FILENAME;//"_filenames.txt";
ifstream ifs(s.c_str());
if (ifs.is_open()) {
while (! ifs.eof()) {
string line;
getline(ifs, line);
AnalyzeFile(tst + line);
}
ifs.close();
}
}
const bool Ergasia1::FillvsKeys() {
bool result= true;
string s= tst + KEYWORDS;
n= 0;
ifstream ifs(s.c_str());
if (ifs.is_open()) {
while (! ifs.eof()) {
string line;
getline(ifs, line);
vsKeys.push_back(line);
}
}
else
result= false;
ifs.close();
return result;
}
const void Ergasia1::ShowData() {
cout << "<messagecollection messages=\"" << n << "\">" << endl;
for(unsigned int i= 0; i < vsStream.size(); i++)
cout << vsStream[i] << endl;
cout << "</messagecollection>" << endl;
}
int main(int argc, char **argv) {
Ergasia1 e;
return 0;
}
Ergasia.h
#include <fstream>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#ifdef _DEBUG
#define DEVEL
#endif
using namespace std;
#ifndef FILENAME
#define FILENAME "_filenames.txt";
#endif
#ifndef KEYWORDS
#define KEYWORDS "keywords.txt"
#endif
#ifndef LING
#define LING "ling"
#endif
#ifndef SPAM
#define SPAM "spam"
#endif
#ifndef ERGASIA1_H
#define ERGASIA1_H
class Ergasia1
{
private:
int n;
string tst;
//static const string FileName;
vector<string> vsKeys;
vector<string> vsStream;
const void AnalyzeFile(const string fn);
const void GetFiles(const string Kind);
const bool FillvsKeys();
const void ShowData();
public:
Ergasia1();
}
#endif
//ERGASIA1_H
int main(int argc, char **argv);
Feature.cpp
#include "Feature.h"
void Feature::setId(int i) {
Id= i;
}
void Feature::setFrequency(int f) {
Frequency= f;
}
void Feature::setDescription(const string d) {
Description= d;
}
int Feature::getId() {
return Id;
}
int Feature::getFrequency() {
return Frequency;
}
string Feature::getDescription() {
return Description;
}
Feature::Feature(int i, int f, const string d) {
setId(i);
setFrequency(f);
setDescription(d);
}
Feature.h
#include <iostream>
using namespace std;
#ifndef FEATURE_H
#define FEATURE_H
class Feature {
private:
int Id;
int Frequency;
string Description;
public:
void setId(int i);
void setFrequency(int f);
void setDescription(const string d);
int getId();
int getFrequency();
string getDescription();
Feature(int i, int f, const string d);
}
#endif
//FEATURE_H
thats the files i created . any help will be appreciate . thanks in advance my friends .