469,568 Members | 1,371 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

system clear in c++

254 100+
i have a function that clear the screen and then display array to cout.
i compiled no error no warning, i run it, the screen really get "clear" but it does not display anything to cout, and it "clear screen" to blanks for 2 seconds, the screen return to this :



Here is my coding:
Expand|Select|Wrap|Line Numbers
  1. /* screen.h */
  2. #ifndef _SCREEN_H_
  3. #define _SCREEN_H_
  4. #include <string>
  5. #include <iostream>
  6. #include <fstream>
  7. #include <cstdlib>
  8.  
  9. #include "array2d.h"
  10.  
  11. namespace Game{
  12.     using namespace std;
  13.     class Screen{
  14.         public:
  15.         Screen(): Xsize(80) , Ysize (23), myArray (Xsize,Ysize){};
  16.  
  17.         ~Screen(){}
  18.  
  19.         /* clear the previous screen and display new screen image with Xsize Ysize */
  20.         void Paint(){
  21.  
  22.             /* clear the screen */
  23.             system("clear");
  24.  
  25.             // and then display the screen with width and height
  26.  
  27.             for(unsigned y = 0; y < Ysize; y++){
  28.                 for(unsigned x = 0; x < Xsize; x++){
  29.                     cout << myArray.Get(Xsize , Ysize);
  30.                 }
  31.             }
  32.         }
  33.  
  34.         private:
  35.         unsigned Xsize;
  36.         unsigned Ysize;
  37.         Array2D<char> myArray;
  38.         string status;
  39.  
  40.  
Expand|Select|Wrap|Line Numbers
  1. /* testgame.cpp */
  2. #include <iostream>
  3. #include <string>
  4. #include "screen.h"
  5. #include "array2d.h"
  6.  
  7. using namespace std;
  8. using namespace Game;
  9.  
  10. int main(){
  11.         Screen s;
  12.         s.Paint();
  13.  
  14.         cout << "Testing screen display..." << endl;
  15.  
  16.     return 0;
  17. }
  18.  
I insist want to use system("clear"), but i guess the problem is within the function Paint() where after system("clear"), it cannot continue to execute.

What's the problem?
Please help.
thanks.
Nicky Eng.
Dec 12 '06 #1
2 26802
DeMan
1,806 1GB
This may nopt be the source of ur prob but methinks:
cout << myArray.Get(Xsize , Ysize);

should be
cout << myArray.Get(x , y);

firstly Xsize & Ysize are probably outside the bounds of the array (because the indexing starts at 0, and secondly I assume you are trying to loop through all the elemnts in the array
Dec 12 '06 #2
nickyeng
254 100+
thanks man.

Nick
Dec 13 '06 #3

Post your reply

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

Similar topics

reply views Thread by Peter | last post: by
18 posts views Thread by Tim Mierzejewski | last post: by
1 post views Thread by manoj.bhosale | last post: by
9 posts views Thread by /* frank */ | last post: by
22 posts views Thread by mp | last post: by
1 post views Thread by Shawn Minisall | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.