c++.dos - Casting Error using disp_printf, disp_puts
- Jaimie (39/39) Jun 26 2005 I am just starting to learn C++ and am working on some DOS console apps ...
- Walter (3/4) Jun 26 2005 disp_printf's first argument is a char*, not an int.
- Cesar Rabak (13/30) Jun 27 2005 Jaimie,
I am just starting to learn C++ and am working on some DOS console apps for the
class I am taking. I would like to use the disp.h functions to handle drawing
and writing to the console, but I've run into a problem with type casting that I
just don't know enough to solve, or even ask the right question.
I understand that I need to do some sort of type conversion here, from int to
string, but I can't figure out how to do this in the context of the disp.h
functions...
Here's the error:
D:\DM\work>dmc problem.cpp
disp_move(5,0); disp_puts("thingInt is "); disp_printf(thingInt);
^
problem.cpp(21) : Error: need explicit cast for function parameter 1 to get
from: int
to : char *
--- errorlevel 1
Here's code that generates the error:
// A really simple problem... I hope
//Library Includes
#include "iostream.h"
#include "iomanip.h"
#include "disp.h"
//Main Body
int main()
{
// Variable Declarations
int thingInt = 0; // an Integer
// Open Display, Clear the screen
disp_open();
disp_move(0,0); // move cursor to upper left corner
disp_eeop(); // clear screen
cout << "Enter a value for thingInt: ";
cin >> thingInt;
// This is where the error is generated...
disp_move(5,0); disp_puts("thingInt is "); disp_printf(thingInt);
// Clean Up
disp_close();
return 0;
}
Jaimie
Jun 26 2005
"Jaimie" <Jaimie_member pathlink.com> wrote in message
news:d9nt58$q21$1 digitaldaemon.com...
disp_move(5,0); disp_puts("thingInt is "); disp_printf(thingInt);
disp_printf's first argument is a char*, not an int.
Jun 26 2005
Jaimie escreveu:
I am just starting to learn C++ and am working on some DOS console apps for the
class I am taking. I would like to use the disp.h functions to handle drawing
and writing to the console, but I've run into a problem with type casting that
I
just don't know enough to solve, or even ask the right question.
I understand that I need to do some sort of type conversion here, from int to
string, but I can't figure out how to do this in the context of the disp.h
functions...
Here's the error:
D:\DM\work>dmc problem.cpp
disp_move(5,0); disp_puts("thingInt is "); disp_printf(thingInt);
^
problem.cpp(21) : Error: need explicit cast for function parameter 1 to get
from: int
to : char *
--- errorlevel 1
Jaimie,
The disp_printf function is supposed to work in a similar fashion as the
vanilla stdio printf. Rather than doing the above, try this (caveat: not
tested):
disp_move(5,0); disp_printf("thingInt is %d", thingInt);
Also, I'm not sure if the mixing of cout and disp_* functions will
coordinate well. In dubio, change the cout call to a disp_printf one.
You _may_ have to manage the flushing of buffers in order to see the
printouts in the way you want.
HTH
--
Cesar Rabak
Jun 27 2005









"Walter" <newshound digitalmars.com> 