How to get over 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:

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

// write text in 4 corners of the screen

clrscr(); // function call
gotoxy(10,10); // function call
cout << "at 10,10";
gotoxy(10,20); // function call
cout << "at 10,20";
gotoxy(20,10); // function call
cout << "at 20,10";
gotoxy(20,20); // function call
cout << "at 20,20";
return 0;
}


// function definition -- requires windows.h
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);
}


// function definition -- requires process.h
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.
 
A

ais523

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:

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

// write text in 4 corners of the screen

clrscr(); // function call
gotoxy(10,10); // function call
cout << "at 10,10";
gotoxy(10,20); // function call
cout << "at 10,20";
gotoxy(20,10); // function call
cout << "at 20,10";
gotoxy(20,20); // function call
cout << "at 20,20";
return 0;
}


// function definition -- requires windows.h
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);
}


// function definition -- requires process.h
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.

The code is C++, not C, and so you've posted to the wrong newsgroup.
Even if cout were defined in C (it isn't unless you've done it
yourself), you couldn't bitshift it by a string. The definition of
gotoxy() could theoretically work in standard C with appropriate
headers and libraries, but based on the identifiers and the comment
before it I'd say it was a nonstandard Windows console routine, and
therefore offtopic. The #error directive in eh.h is actually trying to
help you by letting you know that the code only works in C++ (I suspect
that if you took the code to a different operating system and compiled
it as C++, if you had the same headers, you'd get a different #error
directive telling you that the code only worked under a Windows system,
or something to that effect). The definition of clrscr() is strictly
portable but will behave in an implementation-defined manner if called
(although it might quite possibly work on the system you use), and the
comment at the start is misleading because system() requires stdlib.h,
not process.h. // comments don't survive line-wrapping and aren't valid
in C89, so posting them to comp.lang.c is generally unwise.

At this point, many regulars would set followups to comp.lang.c++, but
I don't think you'll have any luck there either.

I don't know what a 'word cl' is but it's worth thinking about whether
you need one at all, as it reduces the portability of your code. As so
many people use C in all sorts of different contexts and different
systems, there are many newsgroups available. comp.lang.c is only for C
programs or sections of C programs which are portable across all C
systems; if there was just one newsgroup for all C questions, it would
be much harder to find the relevant questions/experts. It is also not
for C++, and AFAIK comp.lang.c++ is only for standard portable C++, so
you'll have to find a new program to work from or a different newsgroup.
 

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

Forum statistics

Threads
473,815
Messages
2,569,702
Members
45,492
Latest member
juliuscaesar

Latest Threads

Top