473,473 Members | 2,286 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

warning about character const

254 Contributor
Hi all,
I have this warning in my code, i dont know which part of it need to change ...
It keeps give me this warning message :



here is my code:
Expand|Select|Wrap|Line Numbers
  1. /* hero.h */
  2. #ifndef _HERO_H_
  3. #define _HERO_H_
  4. #include <iostream>
  5. #include <string>
  6. #include "screen.h"
  7. #include "terrain.h"
  8.  
  9. namespace Game {
  10.     using namespace std;
  11.     class Hero{
  12.         public:
  13.         Hero(){
  14.             posX = 2;
  15.             posY = 2;
  16.             health = 100;
  17.             scr.setStatus("Health : 100%");
  18.         }
  19.  
  20.         int getHealth(){
  21.             return health;
  22.         }
  23.  
  24.         bool testAlive(){
  25.             if(health==0){
  26.                 return false;
  27.             }else{
  28.                 return true;
  29.             }
  30.         }
  31.  
  32.         void moving(){
  33.             char c;
  34.  
  35.             system("stty raw -echo");
  36.             cin.get(c);
  37.             system("stty raw -echo");
  38.  
  39.             if(c=='u' || c=='U'){
  40.                     if(terr.Move(posX,posY-1)==true){
  41.                         posY = posY - 1;
  42.                         health = health - 1;
  43.                     }else{
  44.                         health = health - 5;
  45.                         scr.setStatus("You ran into a Wall!");
  46.                         scr.Beep();
  47.  
  48.                     }
  49.             }else if(c=='d' || c=='D'){
  50.  
  51.                     if(terr.Move(posX,posY-1)==true){
  52.                         posY = posY + 1;
  53.                         health = health - 1;
  54.  
  55.                     }else{
  56.                         scr.setStatus("You ran into a Wall!");
  57.                         scr.Beep();
  58.                         health = health - 5;
  59.                     }
  60.             }else if(c=='r' || c=='R'){
  61.                     if(terr.Move(posX,posY-1)==true){
  62.                         posX = posX + 1;
  63.                         health = health - 1;
  64.  
  65.                     }else{
  66.                         scr.setStatus("You ran into a Wall!");
  67.                         scr.Beep();
  68.                         health = health - 5;
  69.                     }
  70.             }else if(c=='l' || c=='L'){
  71.                     if(terr.Move(posX,posY-1)==true){
  72.                         posX = posX - 1;
  73.                         health = health - 1;
  74.  
  75.                     }else{
  76.                         scr.setStatus("You ran into a Wall!");
  77.                         scr.Beep();
  78.                         health = health - 5;
  79.                     }
  80.  
  81.             }
  82.         }
  83.  
  84.         void DrawHero(){
  85.             scr.Insert(posX,posY,'H');
  86.         }
  87.  
  88.         private:
  89.  
  90.             int posX;
  91.             unsigned posY;
  92.             unsigned health;
  93.             Screen scr;
  94.             Terrain terr;
  95.     };
  96. }
  97. #endif
  98.  
Dec 12 '06 #1
5 1894
DeMan
1,806 Top Contributor
The problem is in screen.h and given the line number given is 91, I assume is now more complex than in your previous post, Though i suspect it may be to do with how you use your variables xSize & ySize.


The Error Messages literally mean:
in the file fou include at line 7 of hero.h the following problem occurs:
at (or near) line 91 char 12 of screen.h .......
Dec 12 '06 #2
nickyeng
254 Contributor
i have this :

Expand|Select|Wrap|Line Numbers
  1.     void Beep(){
  2.             cout << '0x07';
  3.         }
  4.  
the warning is about cout << '0x07';.

i wanna make the screen somehow beep.
the code above correct to so?
Dec 13 '06 #3
DeMan
1,806 Top Contributor
I've always been a fan of printf, so I don't know too much about cout. your statement
i wanna make the screen somehow beep.
Doesn't make much sense to me....my screen displays things, my speakers make noise.....
Dec 14 '06 #4
Ganon11
3,652 Recognized Expert Specialist
There is a simple escape sequence you can use with cout to make a beep, according to http://msdn2.microsoft.com/en-us/library/6aw8xdf2.aspx

Just cout << "\a"; and a beep should sound.
Dec 14 '06 #5
Banfa
9,065 Recognized Expert Moderator Expert
i have this :

Expand|Select|Wrap|Line Numbers
  1.     void Beep(){
  2.             cout << '0x07';
  3.         }
  4.  
the warning is about cout << '0x07';.

i wanna make the screen somehow beep.
the code above correct to so?
The problem is the '0x07', this is a character constant because it uses single quotes '...' . Now I assume you are trying to output character value 7 which is BEL and normally plays a beep through the PC speaker, however '0x07' is not a single character, you need an escape sequence, that is / followed by various options to produce a single character.

For istance

/r - carridge return
/n - new line
/t - tab

to name the well know ones but you can also have the following

/ooo - character with the octal value ooo
/xhh - character with the hexidecimal value hh

so
instead of '0x07' you should have used '/x07' or '/7'
Dec 14 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: thule | last post by:
Okay, thanks to John (THANK YOU SO MUCH). I switched all my header files over to using the new Standard <iostream> and included the using namespace std; . This seems to have fixed all the errors I...
3
by: Eric Lilja | last post by:
Hello, I have a few global variables in my program. One of them holds the name of the application and it's defined in a header file globals.hpp (and the point of definition also happen to be the...
6
by: Jason | last post by:
I have a function (Inet_ntop) that returns const char * and if I try to assign that return value to a char * variable, I get the gcc error message: warning: assignment discards qualifiers from...
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
43
by: Anitha | last post by:
Hi I observed something while coding the other day: if I declare a character array as char s, and try to use it as any other character array..it works perfectly fine most of the times. It...
3
by: Bas Wassink | last post by:
Hello there, I'm having trouble understanding a warning produced by 'splint', a code-checker. The warning produced is: keywords.c: (in function keyw_get_string) keywords.c:60:31: Released...
29
by: Daniel Rudy | last post by:
Hello, Consider the following code fragment: fileptr = fopen(param->filename, "r"); if (fileptr == NULL) { error("digest.c: digest_file: Open File ", errno); return(-2); }
12
by: Howard Kaikow | last post by:
In the code below, ALL the lines that start with PPTfile << are getting the following error at build time. "//i:\C++\C++Code\FileOperations\Form1.h(127) : warning C4800: 'System::String __gc *'...
17
by: B. Williams | last post by:
I am receiving two warnings in my code and can't figure out why. Will someone look at this and tell me what I have done wrong? #include <iostream> using std::cout; #include <string> ...
6
by: subramanian | last post by:
Consider the following program: #include <stdio.h> void myfn(const int **a) { static int i, j, k; a = &i; a = &j;
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.