![]() |
|
|||||||
![]() |
|
|
Thread Tools | Display Modes |
|
#2
|
|||
|
|||
|
Re: Error while compiling program
There is a compilor error.The copy of the program is annexed.
#include <iostream.h> #include <stdlib.h> #include <errno.h> #ifndef LINE_NUM_H #define LINE_NUM_H #include "line_num.h" int main() { int _LINE_NUM; { cout<<"This is the line number:"<<_LINE_NUM <<endl; cout<<"line number is:"<<_LINE_NUM"," <<FILE NAME <<endl; cout<<"The Compiler gives a _cplusplus value of:"; cin>>_LINE_NUM; return 0; } } #endif Pl. have some advice. |
|
#3
|
||||
|
||||
|
Re: Error while compiling program
What compiler are you using?? What is declared within line_num.h?? What compiler errors are being generated??
Code:
cout<<"This is the line number:"<<_LINE_NUM <<endl; Code:
cout<<"line number is:"<<_LINE_NUM"," <<FILE NAME <<endl; really old compilers don't have the std namespace and use the old style headers. If you're using a newer modern compiler, change the includes Code:
#include <iostream> #include <cstdlib> #include <cerrno> using namespace std; ... |
| The Following User Says Thank You to hobbyist For This Useful Post: | ||
shabbir (06-11-2012) | ||
|
#5
|
||||
|
||||
|
Re: Error while compiling program
The header file, line_num.h, should only be used for declaring typedefs, classes, global variables (if any), and function prototypes. function main() belongs in a source file such as .c or .cpp
I'm not exactly sure what you're wanting to do. If you're wanting to print the macros __LINE__, __FILE__, and _cplusplus, then maybe try Code:
#ifdef _cplusplus
#define is_cpp 1
#else
#define is_cpp 0
#endif
cout << "this file is: " << __FILE__
<< "\n"
<< "this line is: " << __LINE__
<< "\n"
<< "_cplusplus defined is: " << is_cpp;
|
|
#7
|
||||
|
||||
|
Re: Error while compiling program
you'll need to trap any errors and take steps programmatically to rectify/report them. I don't know if turbo has try, catch, and throw or not but you might mill over the reference to see how they work. If your application is a debug build, you might also look into using assert. Lastly, you might try a macro in your header... maybe something like
note: \ is intentional when spanning multiple lines; without it, the compiler will protest. Code:
// take 3 arguments, the line near the error,
// the source file where the error occured, and
// whether or not to clear the input stream
#define errorState(errline, errfile, errflag) { \
if(errflag == true) { \
cin.clear(); \
while(cin.get() != '\n'){} \
} \
cout << "error on line: " \
<< errline \
<< "\nin file: " \
<< errfile; \
} \
Code:
int n; cout << "Enter an integer: "; if(!(cin >> n)) errorState(__LINE__, __FILE__, true); |
|
#9
|
||||
|
||||
|
Re: Error while compiling program
it is required to span multiple lines
Code:
printf("hello \
world"); // okay
printf("hello
world"); // compiler error
![]() |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
|
|||||||||||||||||||||||||||||||||||