I wrote my first program in c++ and ended up with this compilation error, please help me out.
In file included from /usr/lib/gcc/i486-linux/4.0.1/../../../../include/c++/4.0.1/backward/iostream.h:31, from prog.cpp:1: /usr/lib/gcc/i486-linux/4.0.1/../../../../include/c++/4.0.1/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the header for the header for C++ includes, or instead of the deprecated header . To disable this warning use -Wno-deprecated. prog.cpp:2:18: error: conio.h: No such file or directory prog.cpp:11:4: warning: no newline at end of file prog.cpp:3: error: '::main' must return 'int' prog.cpp: In function 'int main()': prog.cpp:4: error: 'clrscr' was not declared in this scope prog.cpp:10: error: 'getch' was not declared in this scope
1 Like
@nsingh1995 >> You are using outdated style for headers. Moreover conio.h
is not a standard header file. Refer to [this][1]
EDIT: See how I have modified your
[2], which is now correct!
#include<iostream> // No iostream.h after standardization of C++
using namespace std; // the standard namespace, read more about namespace on the internet
// or just assume for the time being that you have to write this for
// being able to use cout and cin
int main() { // int main() is the proper definition of main() in C++
int n;
cin>>n;
while(!(n==42)) {
cout<<n<<endl; // a new line after each output, similar to printf("%d\n", n);
// endl is similar to the '\n'
cin>>n;
}
// No clrscr(), no getch() as they are both included in conio.h
// which is not a standard header file, so we omit both!
// you can use a dummy variable to hold the screen as you've asked
// int fake_variable; cin>>fake_variable;
return 0;
}
[1]: http://discuss.codechef.com/questions/10195/compilation-error-which-using-iostreamh-and-conioh-in-c/10198
[2]: http://www.codechef.com/viewsolution/2177300
4 Likes
thanku for thisā¦
so how am i supposd to hold the o/p screen?can u link me to somthin to get updated with this standardisationā¦i learnt these header file in my +1 nd now i hav just done my 1st yr so mayb iv forgotten many thingsā¦the second line i hv nevr seen this kinda thing will i have to use this in my evry program?
help will really be appreciated
try system(āPAUSEā) instead of getch()
1 Like
Modified the code again with answer to your query.
For other queries, I would recommend download āThe C++ Programming Languageā by Bjarne Stroustrup, the creator of C++. And, keep practicing the problems here, and asking just like you did 
#include
using namespace std; // important to use as for ansi c
int main()
{
int i,n;
cin >> n ;
for(i=1;i<=n;i++)
{
cout <<" Value of i " << i << endl;
}
return 0 ;
}