944,080 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 657
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Nov 7th, 2009
0

Compiling Errors

Expand Post »
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
C++ Syntax (Toggle Plain Text)
  1.  
  2. #include "Ergasia1.h"
  3. #include "Feature.h"
  4.  
  5. using namespace std;
  6.  
  7. Ergasia1::Ergasia1()
  8. {
  9. #ifdef DEVEL
  10. tst= "../../";
  11. #else
  12. tst= "./";
  13. #endif
  14.  
  15. bool AllOK= FillvsKeys();
  16. if (AllOK) {
  17. GetFiles(LING);
  18. GetFiles(SPAM);
  19. ShowData();
  20. }
  21. else
  22. cout << "Incorrect Installation!" << endl;
  23. }
  24.  
  25. const void Ergasia1::AnalyzeFile(const string fn) {
  26. string fname= fn.substr(tst.length());
  27. size_t pos= fname.find_first_of("/");
  28. string kind= "";
  29. if (pos != string::npos)
  30. kind= fname.substr(0, pos);
  31. int KeywordsFound= 0;
  32. ifstream ifs(fn.c_str());
  33. if (ifs.is_open()) {
  34. n++;
  35. vector<Feature> vf;
  36.  
  37. while (! ifs.eof()) {
  38. string line;
  39. getline(ifs, line);
  40.  
  41. for (unsigned int i= 0; i < vsKeys.size(); i++) {
  42. string key= vsKeys[i];
  43. if (line.find(key) != string::npos) {
  44. bool found= false;
  45. for (unsigned int j= 0; j < vf.size(); j++)
  46. if (vf[j].getDescription().compare(key) == 0) {
  47.  
  48. int x= vf[j].getFrequency();
  49. vf[j].setFrequency(++x);
  50. found= true;
  51. break;
  52. }
  53. if (! found) {
  54.  
  55. Feature *f= new Feature(i, 1, key);
  56. vf.push_back(*f);
  57. KeywordsFound++;
  58. }
  59. }
  60. }
  61. }
  62. ifs.close();
  63. ostringstream osst;
  64. osst << "<message file=\"" << fname <<"\" category=\"" << kind << "\" features=\"" << KeywordsFound << "\">";
  65. vsStream.push_back(osst.str());
  66. osst.flush();
  67. for (unsigned int i= 0; i < vf.size(); i++) {
  68. ostringstream ossb;
  69. ossb << "<feature id=\"" << vf[i].getId() << "\" freq=\"" << vf[i].getFrequency() << "\"> " << vf[i].getDescription() << " </feature>";
  70. vsStream.push_back(ossb.str());
  71. ossb.flush();
  72. }
  73. ostringstream osse;
  74. osse << "</message>";
  75. osse.flush();
  76.  
  77. }
  78. }
  79.  
  80. const void Ergasia1::GetFiles(const string Kind) {
  81. string s= tst + Kind + FILENAME;//"_filenames.txt";
  82. ifstream ifs(s.c_str());
  83. if (ifs.is_open()) {
  84. while (! ifs.eof()) {
  85. string line;
  86. getline(ifs, line);
  87. AnalyzeFile(tst + line);
  88. }
  89. ifs.close();
  90. }
  91. }
  92.  
  93. const bool Ergasia1::FillvsKeys() {
  94. bool result= true;
  95. string s= tst + KEYWORDS;
  96. n= 0;
  97. ifstream ifs(s.c_str());
  98. if (ifs.is_open()) {
  99. while (! ifs.eof()) {
  100. string line;
  101. getline(ifs, line);
  102. vsKeys.push_back(line);
  103. }
  104. }
  105. else
  106. result= false;
  107. ifs.close();
  108. return result;
  109. }
  110.  
  111. const void Ergasia1::ShowData() {
  112. cout << "<messagecollection messages=\"" << n << "\">" << endl;
  113. for(unsigned int i= 0; i < vsStream.size(); i++)
  114. cout << vsStream[i] << endl;
  115. cout << "</messagecollection>" << endl;
  116. }
  117.  
  118. int main(int argc, char **argv) {
  119. Ergasia1 e;
  120. return 0;
  121. }



Ergasia.h
C++ Syntax (Toggle Plain Text)
  1. #include <fstream>
  2. #include <string>
  3. #include <vector>
  4. #include <iostream>
  5. #include <sstream>
  6.  
  7. #ifdef _DEBUG
  8. #define DEVEL
  9. #endif
  10.  
  11. using namespace std;
  12.  
  13. #ifndef FILENAME
  14. #define FILENAME "_filenames.txt";
  15. #endif
  16.  
  17. #ifndef KEYWORDS
  18. #define KEYWORDS "keywords.txt"
  19. #endif
  20.  
  21. #ifndef LING
  22. #define LING "ling"
  23. #endif
  24.  
  25. #ifndef SPAM
  26. #define SPAM "spam"
  27. #endif
  28.  
  29. #ifndef ERGASIA1_H
  30. #define ERGASIA1_H
  31.  
  32. class Ergasia1
  33. {
  34. private:
  35. int n;
  36. string tst;
  37. //static const string FileName;
  38. vector<string> vsKeys;
  39. vector<string> vsStream;
  40. const void AnalyzeFile(const string fn);
  41. const void GetFiles(const string Kind);
  42. const bool FillvsKeys();
  43. const void ShowData();
  44.  
  45. public:
  46. Ergasia1();
  47. }
  48. #endif
  49. //ERGASIA1_H
  50.  
  51. int main(int argc, char **argv);


Feature.cpp
C++ Syntax (Toggle Plain Text)
  1. #include "Feature.h"
  2.  
  3. void Feature::setId(int i) {
  4. Id= i;
  5. }
  6.  
  7. void Feature::setFrequency(int f) {
  8. Frequency= f;
  9. }
  10.  
  11. void Feature::setDescription(const string d) {
  12. Description= d;
  13. }
  14.  
  15. int Feature::getId() {
  16. return Id;
  17. }
  18.  
  19. int Feature::getFrequency() {
  20. return Frequency;
  21. }
  22.  
  23. string Feature::getDescription() {
  24. return Description;
  25. }
  26.  
  27. Feature::Feature(int i, int f, const string d) {
  28. setId(i);
  29. setFrequency(f);
  30. setDescription(d);
  31. }




Feature.h
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3. #ifndef FEATURE_H
  4. #define FEATURE_H
  5.  
  6. class Feature {
  7. private:
  8. int Id;
  9. int Frequency;
  10. string Description;
  11. public:
  12. void setId(int i);
  13. void setFrequency(int f);
  14. void setDescription(const string d);
  15. int getId();
  16. int getFrequency();
  17. string getDescription();
  18. Feature(int i, int f, const string d);
  19. }
  20. #endif
  21. //FEATURE_H


thats the files i created . any help will be appreciate . thanks in advance my friends .
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
konefsta is offline Offline
9 posts
since Nov 2009
Nov 7th, 2009
0
Re: Compiling Errors
Just looking briefly, I see one error on line #14 of ergasia.h:
#define FILENAME "_filenames.txt";
Reputation Points: 237
Solved Threads: 117
Practically a Posting Shark
Clinton Portis is offline Offline
822 posts
since Oct 2005
Nov 7th, 2009
0
Re: Compiling Errors
i still have the same errors .
any other ideas ?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
konefsta is offline Offline
9 posts
since Nov 2009
Nov 7th, 2009
0
Re: Compiling Errors
Seem to be missing semicolons after your class declarations in the headers:
C++ Syntax (Toggle Plain Text)
  1. class Feature {
  2. private:
  3. int Id;
  4. int Frequency;
  5. string Description;
  6. public:
  7. void setId(int i);
  8. void setFrequency(int f);
  9. void setDescription(const string d);
  10. int getId();
  11. int getFrequency();
  12. string getDescription();
  13. Feature(int i, int f, const string d);
  14. }; <-------------- (and in your other header too)

Oh yeah, and get rid of that declaration of main in the header file. Keep the one in the cpp file.
Last edited by jonsca; Nov 7th, 2009 at 12:32 pm.
Sponsor
Featured Poster
Reputation Points: 1165
Solved Threads: 578
Quantitative Phrenologist
jonsca is offline Offline
4,271 posts
since Sep 2009
Nov 7th, 2009
0
Re: Compiling Errors
i still have the same errors
Reputation Points: 10
Solved Threads: 0
Newbie Poster
konefsta is offline Offline
9 posts
since Nov 2009
Nov 7th, 2009
0
Re: Compiling Errors
i am thinking , is it possible that i am missing a file or something ?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
konefsta is offline Offline
9 posts
since Nov 2009
Nov 7th, 2009
0
Re: Compiling Errors
You need to compile them at the same time as they are dependent on one another e.g., g++ -o myprogram ergasia.cpp feature.cpp depending on what compiler you are using. I suppose you could compile them separately to .o files and link them together but doing it in one step is easier.
Sponsor
Featured Poster
Reputation Points: 1165
Solved Threads: 578
Quantitative Phrenologist
jonsca is offline Offline
4,271 posts
since Sep 2009
Nov 8th, 2009
0
Re: Compiling Errors
how can i compile them in the same time ? i am using Dev-C++ and wxDev-C++
Reputation Points: 10
Solved Threads: 0
Newbie Poster
konefsta is offline Offline
9 posts
since Nov 2009
Nov 8th, 2009
0
Re: Compiling Errors
?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
konefsta is offline Offline
9 posts
since Nov 2009
Nov 8th, 2009
0
Re: Compiling Errors
I haven't used it since it's infancy in the 90's (dating myself here,I'm sure it's matured since then), but basically you need to start a console project (screenshot here: http://en.wikiversity.org/wiki/Insta...ng_Dev-C%2B%2B) and incorporate those headers and cpp files into the project by right clicking the project name.
I'm sure there are plenty of other folks on here who know Dev-C++ like the back of their hand, so post back if you're still having trouble.
Sponsor
Featured Poster
Reputation Points: 1165
Solved Threads: 578
Quantitative Phrenologist
jonsca is offline Offline
4,271 posts
since Sep 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Binary file functions
Next Thread in C++ Forum Timeline: help please!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC