I found error in compiling the file. The program file is annexed. (B.N.ROHIT) Kindly have your advice on it early.
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.
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; _LINE_NUM hasn't been initialized yet Code: cout<<"line number is:"<<_LINE_NUM[b]","[/b] <<FILE NAME <<endl; you're missing << between _LINE_NUM and "," and FILE NAME has a white space. 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; ...
I am using Turbo C compiler.In line_num.h I have used " Int main() { int_LINE_NUM; return 0; { Actually I have not initialized the variable. That is my mistake.
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; _cplusplus doesn't seem to exist on the compiler I'm currently using. :|
I desire to place the header file into the .cpp file for knowing the error line number exactly and nothing else.
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; \ } \ in your cpp file, you'd do something like Code: int n; cout << "Enter an integer: "; if(!(cin >> n)) errorState(__LINE__, __FILE__, true); hope that helps
it is required to span multiple lines Code: printf("hello \ world"); // okay printf("hello world"); // compiler error in the #define errorState macro, \ is needed because the code spans multiple lines; that's all.