How to fix this error?

M

mario.zoric

Hi to all!
I have one big problem. I have written some code and I want to program
at the end looks good but theres one uninspected error.
What's going on?
I have written code for programm that needs to do input, output and
searching, for looking better i wanted to use simple DOS word cls
but(!!!!) in C/C++ there i cant use it. so I looked over the internet
and nearest i could find it's this code:
#include <iostream.h>
#include <windows.h>
#include <process.h>

void gotoxy(int, int);
void clrscr();
int main(){



clrscr();
gotoxy(10,10);
cout << "at 10,10";
gotoxy(10,20);
cout << "at 10,20";
gotoxy(20,10);
cout << "at 20,10";
gotoxy(20,20);
cout << "at 20,20";
return 0;

}


void gotoxy(int x, int y){

HANDLE hConsoleOutput;
COORD dwCursorPosition;
cout.flush();
dwCursorPosition.X = x;
dwCursorPosition.Y = y;
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);

}


void clrscr(){
system("cls");

}

I have compiled it in Microsoft Visual Studio 6.0 and there i had
error, it said :
c:\program files\microsoft visual studio\vc98\include\eh.h(32) : fatal
error C1189: #error : "eh.h is only for C++!"

I looked for line where it is and that becomes that it's in standard
Microsoft Visual Studio 6.0 header file eh.h
line around the error are this:

#ifndef __cplusplus
#error "eh.h is only for C++!"
#endif

So my question is what i have to do to fix this error. I tried a lot of
combinations but I failed.

Thank You for help.
 
I

Ivan Vecerina

: Hi to all!
: I have one big problem. I have written some code and I want to program
: at the end looks good but theres one uninspected error.
....
: I have compiled it in Microsoft Visual Studio 6.0 and there i had
: error, it said :
: c:\program files\microsoft visual studio\vc98\include\eh.h(32) : fatal
: error C1189: #error : "eh.h is only for C++!"
:
: I looked for line where it is and that becomes that it's in standard
: Microsoft Visual Studio 6.0 header file eh.h
: line around the error are this:
:
: #ifndef __cplusplus
: #error "eh.h is only for C++!"
: #endif
:
: So my question is what i have to do to fix this error. I tried a lot of
: combinations but I failed.

__cplusplus is normally defined by all C++ compilers (incl. MSVS6),
to help source code check that this is not a C-only compiler.

It looks like your program might be compiled by a C compiler.
Maybe you need to change the extension of your file from
..c to .cpp (or similar) for the environment to handle it
as a C++ file. Or look into your compiler's documentation
how the selection/configuration of the compiler for a
given file or extension.

hth -Ivan
 
I

iftekhar

what is the extension of your source file? if it is not cpp some
compilers compile it as a c file and then __cplusplus is not defined.

may be VC does this.

by the way, the code you are using uses windoes api. i guess it wont
run in pure DOS (like 6.0) (if that is important to you at all). you
can also do the same with the function system()

vois clearscreen(void)
{
#ifdef WIN32 // not sure about this may also be DOS or __DOS__
system("cls");
#else if
system("clear"); // for linux
#endif
}

hope it helps,
iftekhar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,630
Members
45,338
Latest member
41Pearline46

Latest Threads

Top