I need special stuff in my project like system("cls")

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2004
Posts: 15
Reputation: dooda man is an unknown quantity at this point 
Solved Threads: 0
dooda man dooda man is offline Offline
Newbie Poster

I need special stuff in my project like system("cls")

 
1
  #1
May 23rd, 2004
hii, i am computer science student and i am doing win console application program "Project" by c++ compiler "mic visiual 6", the project is like a small data base which stores student names and thier grades and search for names, add, delete,edit and other things. i am asking if i can make it more friendly by putting colors or any special stuff. for example i read in a forum ( system("cls") ) which really helped me in my project and system("pause") too. any one know things like that plzzzz tell me. i need to know these stuff.
another thing.. i read that there is another systems like system("time") if any one know what these systems make plzz help me.:rolleyes:
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 141
Reputation: meabed is on a distinguished road 
Solved Threads: 3
Team Colleague
meabed's Avatar
meabed meabed is offline Offline
Junior Poster

Re: I need special stuff in my project like system("cls")

 
0
  #2
May 24th, 2004
Formatting Output
Formatting output is one of the most important aspects of developing user-friendly programs. C++ offers several conventions that allow a programmer to format output on the screen. The functions that deal with output format are in the standard include file "iomanip.h."

Two common I/O manipulators are setw and setprecision. Setw sets the width of the field allocated for the output. It takes the size of the field (in number of characters) as a parameter. For example, the code:

  1. cout << setw(5) << "H";
  2. generates the following output on the screen (each underscore represents a space):
  3.  
  4. _ _ _ _ H
The setprecision manipulator sets the total number of digits to be displayed when floating point numbers are output. For example, the code:

  1. cout << setprecision(5) << 123.456;
  2.  
  3. generates the following output on the screen:
  4.  
  5. 123.46
The setprecision manipulator can also set the number of decimal places displayed, but first you have to set an ios flag that specifies that it should behave this way. The flag is set with the following statement:

  1. cout.setf(ios::fixed);

Once the flag has been set specifying that floating point output should be fixed, the number you pass as a parameter to setprecision is the number of decimal places displayed. For example, the code:

  1. cout.setf(ios::fixed);
  2. cout << setprecision(5) << 12.345678;
  3.  
  4. generates the following output on the screen:
  5.  
  6. 12.34567
Pausing Output
A frequently encountered problem involves pausing the output of a program so that the output can be read before the output window closes. Use the Execute command on the Build menu to run your program. The Execute command will automatically place a "Press any key to continue..." prompt on the screen when your program terminates. When you have finished with the output, press a key to make the window close.

Clearing the Screen
To clear the entire output window of a program, you must use a system function found in the stdlib.h include file. First, include stdlib.h at the top of your program. Then, just insert the following call whenever you want to clear the screen:

system("CLS");

The program below is an example of how to use this method of clearing the screen.

  1. #include <iostream.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5.  
  6. {
  7. cout << "Text before the clear screen." << endl;
  8. system("CLS");
  9. cout << "Text following the clear screen." << endl;
  10. return 0;
  11. }
Sending Output to the Printer
How you print is now a function of your operating system. To print using Windows 95/98 or NT, you have to get your output to a print manager in the operating system.

To direct output to a printer, you must first open a file stream to send output to. You can do this using the same method that you use to send output to a file. First, declare a variable of type fstream. Then open the stream using the member function, open. Instead of opening the stream using the name of a file, use the name of your printer port, for example, "LPT1."

Once a file stream is open, you can print using the name of the stream variable followed by the << operator and the data you want to send to the printer. Be sure to close the stream when you no longer need to use it.

The example program below will send text to a printer on port LPT1.

  1. #include <fstream.h>
  2.  
  3. int main()
  4.  
  5. {
  6. ofstream print; // stream variable declaration
  7. print.open("LPT1"); // open stream
  8.  
  9. // Print Text (the character ‘\f’ will produce a form feed)
  10. print << "This text will print on the printer.\f";
  11. print.close(); // close stream
  12. return 0;
  13. }
Important Note:
1-Blindly directing text to a printer port assumes some things are true.

It assumes that you have a printer attached to the specified port or that the port is being captured and redirected to a printer.
It assumes that the printer is capable of accepting plain text. For example, a PostScript printer will not print unless the data comes through a PostScript printer driver. The code above does not make use of any drivers.
another example this program traping function key F1 and F2
  1. # include<iostream.h>
  2. # include<conio.h>
  3. void function_key(); //prototype of the function
  4. void main()
  5. {
  6. function_key(); //function call
  7. }
  8. void function_key() //function body
  9. {
  10. int ret;
  11. ret = getch(); //get the ASCII value of the key pressed
  12.  
  13. if (ret == 0)
  14. {
  15. ret = getch()+256;
  16.  
  17. switch(ret) //switch between various values of 'ret'
  18. {
  19. case 315:
  20. cout<<" F1 pressed!\n\n";
  21. break;
  22. case 316:
  23. cout<<"F2 pressed!\n";
  24. break;
  25. case 317:
  26. cout<<"F3 pressed!\n";
  27. break;
  28. case 318:
  29. cout<<"F4 pressed!\n";
  30. break;
  31. case 319:
  32. cout<<"F5 pressed!\n";
  33. break;
  34. case 320:
  35. cout<<"F6 pressed!\n";
  36. break;
  37. case 321:
  38. cout<<"F7 pressed!\n";
  39. break;
  40. case 322:
  41. cout<<"F8 pressed!\n";
  42. break;
  43. case 323:
  44. cout<<"F9 pressed!\n";
  45. break;
  46. case 324:
  47. cout<<"F10 pressed!\n";
  48. break;
  49. default:
  50. cout<<"Non function key was pressed!\n";
  51. break;
  52. }
  53. }
  54. else
  55. cout<<"Non Function Key pressed!\n";
  56.  
  57. }
Real Eyes Realize Real Lies
My Resume
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: I need special stuff in my project like system("cls")

 
0
  #3
May 27th, 2004
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 11
Reputation: MaxC is an unknown quantity at this point 
Solved Threads: 0
MaxC MaxC is offline Offline
Newbie Poster

Re: I need special stuff in my project like system("cls")

 
1
  #4
Jun 2nd, 2004
Wow!
I really can use this stuff too.
Thank a lot.
MSVC++
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: I need special stuff in my project like system("cls")

 
0
  #5
Jun 7th, 2004
You are most welcome.Now there is a full tut on file i/o in the C++ tutorial section :-)
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC