stupid error

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 382
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

stupid error

 
0
  #1
Mar 27th, 2009
idk why i get this error i just do

here is the code i have:
  1. #include "includes.h"
  2.  
  3. int main()
  4. {
  5.  
  6. }

here is the error:
c:\documents and settings\tom\my documents\visual studio 2008\projects\c++ tutorial\c++ tutorial\main.cpp(3) : error C2143: syntax error : missing ';' before 'int'

any ideas?
...
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 211
Reputation: rahul8590 is on a distinguished road 
Solved Threads: 11
rahul8590's Avatar
rahul8590 rahul8590 is offline Offline
Posting Whiz in Training

Re: stupid error

 
0
  #2
Mar 27th, 2009
At the first place i dont know wat r u trying to do here .

Well i guess if you include the main header file also i.e
#include<iostream.h>
u may not get this error.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 382
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

Re: stupid error

 
0
  #3
Mar 27th, 2009
thats included in std_lib_facilities.h, its for a tutorial im doing. mabey the VC++ compiler is just screwing up
...
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 211
Reputation: rahul8590 is on a distinguished road 
Solved Threads: 11
rahul8590's Avatar
rahul8590 rahul8590 is offline Offline
Posting Whiz in Training

Re: stupid error

 
0
  #4
Mar 27th, 2009
yeah .. that sounds k . but did you try this way i mentioned . before ?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 382
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

Re: stupid error

 
0
  #5
Mar 27th, 2009
still does the same thins
...
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,259
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 540
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: stupid error

 
-7
  #6
Mar 27th, 2009
main needs paramaters and needs to return a value, else its not valid standard c++
Last edited by jbennet; Mar 27th, 2009 at 4:03 am.
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 382
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

Re: stupid error

 
0
  #7
Mar 27th, 2009
i tried that and it still doesnt work
...
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 211
Reputation: rahul8590 is on a distinguished road 
Solved Threads: 11
rahul8590's Avatar
rahul8590 rahul8590 is offline Offline
Posting Whiz in Training

Re: stupid error

 
0
  #8
Mar 27th, 2009
well when i ran this program

  1. #include<iostream.h>
  2. int main()
  3. {
  4. }
it didnt give me ne errors .
well i work on codeblocks IDE and GCC compiler i guess
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 979
Reputation: mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice 
Solved Threads: 209
mitrmkar mitrmkar is offline Offline
Posting Shark

Re: stupid error

 
0
  #9
Mar 27th, 2009
Maybe you could post the "includes.h" file?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 382
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

Re: stupid error

 
0
  #10
Mar 27th, 2009
main.cpp:
  1. #include "std_lib_facilities.h"
  2. #include "maindef.h"
  3. #include "date.h"
  4.  
  5. int main(int argc, char* argv[])
  6. {
  7. cout<<"Hello!, "<<argv[0]<<'\n';
  8. keep_window_open(); //the equivilent of cin.get();
  9. return 0;
  10. }

maindef.h:
  1. #ifndef _maindef_h_
  2. #define _maindef_h_
  3.  
  4. #include "std_lib_facilities.h"
  5.  
  6. #define BOOL int
  7. #define NULL 0
  8. #define FALSE NULL
  9. #define TRUE 1
  10.  
  11. template<typename t> class list {
  12. int sz;
  13. t elem;
  14. public:
  15. list() : sz(0), elem(new t[0]){ }
  16. list(int i) : sz(i), elem(new t[i]){ }
  17. list(int i, int val) : sz(i), elem(new t[i])
  18. {
  19. for(int i=0;i>sz;i++) cout<<elem[i];
  20. }
  21.  
  22. list operator[](int i){ return elem[i]; }
  23.  
  24. void printAll(void);
  25. }
  26.  
  27. #endif /* _maindef_h_ */

date.h:
  1. #ifndef _date_h_
  2. #define _date_h_
  3.  
  4. #include "maindef.h"
  5. #include "std_lib_facilities.h"
  6.  
  7. class Date {
  8. //private data members
  9. int y, m, d;
  10.  
  11. //for error checking
  12. class invalid{ };
  13. public:
  14. //constructor
  15. Date(int y, int m, int d);
  16. BOOL check(void);
  17.  
  18. //modifying functions
  19. void add(char ch, int i);
  20.  
  21. //access functions
  22. int year(){ return y; }
  23. int month(){ return m; }
  24. int day(){ return d; }
  25. };
  26.  
  27. #endif /* _date_h_ */

date.cpp:
  1. #include "date.h"
  2. #include "std_lib_facilities.h"
  3. #include "maindef.h"
  4.  
  5. Date::Date(int y, int m, int d)
  6. :y(y), m(m), d(d)
  7. {
  8. if(!check()) throw invalid();
  9. }
  10.  
  11. void Date::add(char ch, int i)
  12. {
  13. int val = 0;
  14.  
  15. if(ch == 'y')
  16. val = 1;
  17. else if(ch == 'm')
  18. val = 2;
  19. else if(ch =='d')
  20. val = 3;
  21. else
  22. error("invalid param called to Date::add()");
  23.  
  24. switch(i)
  25. {
  26. case 1:
  27. y += i;
  28. case 2:
  29. m += i;
  30. case 3:
  31. d += i;
  32. }
  33. }
  34.  
  35. BOOL Date::check(void)
  36. {
  37. if((d<0 || 31>d) && (m<1 || 12>m) && (y<0 || 2009>12) )
  38. return FALSE;
  39. else
  40. return TRUE;
  41. }

maindef.cpp:
  1. #include "maindef.h"
  2. #include "std_lib_facilities.h"
  3.  
  4. list::list(int i, int val)
  5. : sz(i), elem(new t[i])
  6. {
  7. for(int i=0;i>sz;i++)
  8. elem[i] = val;
  9. }
  10.  
  11. void list::printAll(void)
  12. {
  13. for(int i=0;i>sz;i++)
  14. {
  15. cout<<elem[i];
  16. }
  17. }

std_lib_facilities(not writen by me):
  1. /*
  2. simple "Programming: Principles and Practice using C++" course header to
  3. be used for the first few weeks.
  4. It provides the most common standard headers (in the global namespace)
  5. and minimal exception/error support.
  6.  
  7. Students: please don't try to understand the details of headers just yet.
  8. All will be explained. This header is primarily used so that you don't have
  9. to understand every concept all at once.
  10. */
  11.  
  12. #ifndef H112
  13. #define H112 200608L
  14.  
  15. #include<iostream>
  16. #include<fstream>
  17. #include<sstream>
  18. #include<cmath>
  19. #include<cstdlib>
  20. #include<string>
  21. #include<vector>
  22. #include<algorithm>
  23. #include<stdexcept>
  24. using namespace std;
  25.  
  26.  
  27. template<class T> string to_string(const T& t)
  28. {
  29. ostringstream os;
  30. os << t;
  31. return os.str();
  32. }
  33.  
  34. struct Range_error : out_of_range { // enhanced vector range error reporting
  35. int index;
  36. Range_error(int i) :out_of_range("Range error: "+to_string(i)), index(i) { }
  37. };
  38.  
  39.  
  40. // trivially range-checked vector (no iterator checking):
  41. template< class T> struct Vector : public std::vector<T> {
  42. typedef typename std::vector<T>::size_type size_type;
  43. Vector() { }
  44. explicit Vector(size_type n) :std::vector<T>(n) {}
  45. Vector(size_type n, const T& v) :std::vector<T>(n,v) {}
  46.  
  47. T& operator[](unsigned int i) // rather than return at(i);
  48. {
  49. if (i<0||this->size()<=i) throw Range_error(i);
  50. return std::vector<T>::operator[](i);
  51. }
  52. const T& operator[](unsigned int i) const
  53. {
  54. if (i<0||this->size()<=i) throw Range_error(i);
  55. return std::vector<T>::operator[](i);
  56. }
  57. };
  58.  
  59. // disgusting macro hack to get a range checked vector:
  60. #define vector Vector
  61.  
  62. // trivially range-checked string (no iterator checking):
  63. struct String : std::string {
  64.  
  65. String() { }
  66. String(const char* p) :std::string(p) {}
  67. String(const string& s) :std::string(s) {}
  68. String(int sz, char val) :std::string(sz,val) {}
  69. template<class Iter> String(Iter p1, Iter p2) : std::string(p1,p2) { }
  70.  
  71. char& operator[](unsigned int i) // rather than return at(i);
  72. {
  73. if (i<0||size()<=i) throw Range_error(i);
  74. return std::string::operator[](i);
  75. }
  76.  
  77. const char& operator[](unsigned int i) const
  78. {
  79. if (i<0||size()<=i) throw Range_error(i);
  80. return std::string::operator[](i);
  81. }
  82. };
  83.  
  84.  
  85.  
  86. struct Exit : runtime_error {
  87. Exit(): runtime_error("Exit") {}
  88. };
  89.  
  90. // error() simply disguises throws:
  91. inline void error(const string& s)
  92. {
  93. throw runtime_error(s);
  94. }
  95.  
  96. inline void error(const string& s, const string& s2)
  97. {
  98. error(s+s2);
  99. }
  100.  
  101. inline void error(const string& s, int i)
  102. {
  103. ostringstream os;
  104. os << s <<": " << i;
  105. error(os.str());
  106. }
  107.  
  108. #if _MSC_VER<1500
  109. // disgusting macro hack to get a range checked string:
  110. #define string String
  111. // MS C++ 9.0 have a built-in assert for string range check
  112. // and uses "std::string" in several places so that macro substitution fails
  113. #endif
  114.  
  115. template<class T> char* as_bytes(T& i) // needed for binary I/O
  116. {
  117. void* addr = &i; // get the address of the first byte
  118. // of memory used to store the object
  119. return static_cast<char*>(addr); // treat that memory as bytes
  120. }
  121.  
  122.  
  123. inline void keep_window_open()
  124. {
  125. cin.clear();
  126. cout << "Press enter to continue...";
  127. cin.get();
  128. return;
  129. }
  130.  
  131. inline void keep_window_open(string s)
  132. {
  133. if (s=="") return;
  134. cin.clear();
  135. cin.ignore(120,'\n');
  136. for (;;) {
  137. cout << "Please enter \"" << s << "\" to exit\n";
  138. string ss;
  139. while (cin >> ss && ss!=s)
  140. cout << "Please type \"" << s << "\" to exit\n";
  141. return;
  142. }
  143. }
  144.  
  145. // make std::min() and std::max() accessible:
  146. #undef min
  147. #undef max
  148.  
  149. #include<iomanip>
  150. inline ios_base& general(ios_base& b) // to augment fixed and scientific
  151. {
  152. b.setf(ios_base::fmtflags(0),ios_base::floatfield);
  153. return b;
  154. }
  155.  
  156. // run-time checked narrowing cast (type conversion):
  157. template<class R, class A> R narrow_cast(const A& a)
  158. {
  159. R r = a;
  160. if (A(r)!=a) error(string("info loss"));
  161. return r;
  162. }
  163.  
  164.  
  165. inline int randint(int max) { return rand()%max; }
  166.  
  167. inline int randint(int min, int max) { return randint(max-min)+min; }
  168.  
  169. #endif

as i said before, this code is all for a book i bought called "Programming principals and prictice using c++" by Bjarne Stroustrup(the original designer and implementer of c++)
this code has worked before(as far as i can remember)

all your help has and will be apprecieted
...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC