| | |
stupid error
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
idk why i get this error i just do
here is the code i have:
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?
here is the code i have:
c++ Syntax (Toggle Plain Text)
#include "includes.h" int main() { }
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?
...
well when i ran this program
it didnt give me ne errors .
well i work on codeblocks IDE and GCC compiler i guess
C++ Syntax (Toggle Plain Text)
#include<iostream.h> int main() { }
well i work on codeblocks IDE and GCC compiler i guess
main.cpp:
maindef.h:
date.h:
date.cpp:
maindef.cpp:
std_lib_facilities(not writen by me):
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
c++ Syntax (Toggle Plain Text)
#include "std_lib_facilities.h" #include "maindef.h" #include "date.h" int main(int argc, char* argv[]) { cout<<"Hello!, "<<argv[0]<<'\n'; keep_window_open(); //the equivilent of cin.get(); return 0; }
maindef.h:
c++ Syntax (Toggle Plain Text)
#ifndef _maindef_h_ #define _maindef_h_ #include "std_lib_facilities.h" #define BOOL int #define NULL 0 #define FALSE NULL #define TRUE 1 template<typename t> class list { int sz; t elem; public: list() : sz(0), elem(new t[0]){ } list(int i) : sz(i), elem(new t[i]){ } list(int i, int val) : sz(i), elem(new t[i]) { for(int i=0;i>sz;i++) cout<<elem[i]; } list operator[](int i){ return elem[i]; } void printAll(void); } #endif /* _maindef_h_ */
date.h:
c++ Syntax (Toggle Plain Text)
#ifndef _date_h_ #define _date_h_ #include "maindef.h" #include "std_lib_facilities.h" class Date { //private data members int y, m, d; //for error checking class invalid{ }; public: //constructor Date(int y, int m, int d); BOOL check(void); //modifying functions void add(char ch, int i); //access functions int year(){ return y; } int month(){ return m; } int day(){ return d; } }; #endif /* _date_h_ */
date.cpp:
c++ Syntax (Toggle Plain Text)
#include "date.h" #include "std_lib_facilities.h" #include "maindef.h" Date::Date(int y, int m, int d) :y(y), m(m), d(d) { if(!check()) throw invalid(); } void Date::add(char ch, int i) { int val = 0; if(ch == 'y') val = 1; else if(ch == 'm') val = 2; else if(ch =='d') val = 3; else error("invalid param called to Date::add()"); switch(i) { case 1: y += i; case 2: m += i; case 3: d += i; } } BOOL Date::check(void) { if((d<0 || 31>d) && (m<1 || 12>m) && (y<0 || 2009>12) ) return FALSE; else return TRUE; }
maindef.cpp:
c++ Syntax (Toggle Plain Text)
#include "maindef.h" #include "std_lib_facilities.h" list::list(int i, int val) : sz(i), elem(new t[i]) { for(int i=0;i>sz;i++) elem[i] = val; } void list::printAll(void) { for(int i=0;i>sz;i++) { cout<<elem[i]; } }
std_lib_facilities(not writen by me):
c++ Syntax (Toggle Plain Text)
/* simple "Programming: Principles and Practice using C++" course header to be used for the first few weeks. It provides the most common standard headers (in the global namespace) and minimal exception/error support. Students: please don't try to understand the details of headers just yet. All will be explained. This header is primarily used so that you don't have to understand every concept all at once. */ #ifndef H112 #define H112 200608L #include<iostream> #include<fstream> #include<sstream> #include<cmath> #include<cstdlib> #include<string> #include<vector> #include<algorithm> #include<stdexcept> using namespace std; template<class T> string to_string(const T& t) { ostringstream os; os << t; return os.str(); } struct Range_error : out_of_range { // enhanced vector range error reporting int index; Range_error(int i) :out_of_range("Range error: "+to_string(i)), index(i) { } }; // trivially range-checked vector (no iterator checking): template< class T> struct Vector : public std::vector<T> { typedef typename std::vector<T>::size_type size_type; Vector() { } explicit Vector(size_type n) :std::vector<T>(n) {} Vector(size_type n, const T& v) :std::vector<T>(n,v) {} T& operator[](unsigned int i) // rather than return at(i); { if (i<0||this->size()<=i) throw Range_error(i); return std::vector<T>::operator[](i); } const T& operator[](unsigned int i) const { if (i<0||this->size()<=i) throw Range_error(i); return std::vector<T>::operator[](i); } }; // disgusting macro hack to get a range checked vector: #define vector Vector // trivially range-checked string (no iterator checking): struct String : std::string { String() { } String(const char* p) :std::string(p) {} String(const string& s) :std::string(s) {} String(int sz, char val) :std::string(sz,val) {} template<class Iter> String(Iter p1, Iter p2) : std::string(p1,p2) { } char& operator[](unsigned int i) // rather than return at(i); { if (i<0||size()<=i) throw Range_error(i); return std::string::operator[](i); } const char& operator[](unsigned int i) const { if (i<0||size()<=i) throw Range_error(i); return std::string::operator[](i); } }; struct Exit : runtime_error { Exit(): runtime_error("Exit") {} }; // error() simply disguises throws: inline void error(const string& s) { throw runtime_error(s); } inline void error(const string& s, const string& s2) { error(s+s2); } inline void error(const string& s, int i) { ostringstream os; os << s <<": " << i; error(os.str()); } #if _MSC_VER<1500 // disgusting macro hack to get a range checked string: #define string String // MS C++ 9.0 have a built-in assert for string range check // and uses "std::string" in several places so that macro substitution fails #endif template<class T> char* as_bytes(T& i) // needed for binary I/O { void* addr = &i; // get the address of the first byte // of memory used to store the object return static_cast<char*>(addr); // treat that memory as bytes } inline void keep_window_open() { cin.clear(); cout << "Press enter to continue..."; cin.get(); return; } inline void keep_window_open(string s) { if (s=="") return; cin.clear(); cin.ignore(120,'\n'); for (;;) { cout << "Please enter \"" << s << "\" to exit\n"; string ss; while (cin >> ss && ss!=s) cout << "Please type \"" << s << "\" to exit\n"; return; } } // make std::min() and std::max() accessible: #undef min #undef max #include<iomanip> inline ios_base& general(ios_base& b) // to augment fixed and scientific { b.setf(ios_base::fmtflags(0),ios_base::floatfield); return b; } // run-time checked narrowing cast (type conversion): template<class R, class A> R narrow_cast(const A& a) { R r = a; if (A(r)!=a) error(string("info loss")); return r; } inline int randint(int max) { return rand()%max; } inline int randint(int min, int max) { return randint(max-min)+min; } #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
...
![]() |
Similar Threads
- Front Page error when opening .HTM file (HTML and CSS)
- Stupid error!!! (PHP)
- Stupid Error!!! (MySQL)
- OnCalcField modifying its own DataSet - Error (Pascal and Delphi)
- Error when loading a game (Windows NT / 2000 / XP)
- Keep getting stupid ERROR messages (Windows NT / 2000 / XP)
- Some stupid error i cant fix, PLEASE HELP (Java)
Other Threads in the C++ Forum
- Previous Thread: File streams in c++, it compiles but the output is wrong it wont let me enter a file
- Next Thread: void functions
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






