| | |
I need special stuff in my project like system("cls")
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2004
Posts: 15
Reputation:
Solved Threads: 0
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:
another thing.. i read that there is another systems like system("time") if any one know what these systems make plzz help me.:rolleyes:
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:
The setprecision manipulator sets the total number of digits to be displayed when floating point numbers are output. For example, the code:
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:
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:
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.
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.
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
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:
C++ Syntax (Toggle Plain Text)
cout << setw(5) << "H"; generates the following output on the screen (each underscore represents a space): _ _ _ _ H
C++ Syntax (Toggle Plain Text)
cout << setprecision(5) << 123.456; generates the following output on the screen: 123.46
C++ Syntax (Toggle Plain Text)
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:
C++ Syntax (Toggle Plain Text)
cout.setf(ios::fixed); cout << setprecision(5) << 12.345678; generates the following output on the screen: 12.34567
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.
C++ Syntax (Toggle Plain Text)
#include <iostream.h> #include <stdlib.h> int main() { cout << "Text before the clear screen." << endl; system("CLS"); cout << "Text following the clear screen." << endl; return 0; }
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.
C++ Syntax (Toggle Plain Text)
#include <fstream.h> int main() { ofstream print; // stream variable declaration print.open("LPT1"); // open stream // Print Text (the character â\fâ will produce a form feed) print << "This text will print on the printer.\f"; print.close(); // close stream return 0; }
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
C++ Syntax (Toggle Plain Text)
# include<iostream.h> # include<conio.h> void function_key(); //prototype of the function void main() { function_key(); //function call } void function_key() //function body { int ret; ret = getch(); //get the ASCII value of the key pressed if (ret == 0) { ret = getch()+256; switch(ret) //switch between various values of 'ret' { case 315: cout<<" F1 pressed!\n\n"; break; case 316: cout<<"F2 pressed!\n"; break; case 317: cout<<"F3 pressed!\n"; break; case 318: cout<<"F4 pressed!\n"; break; case 319: cout<<"F5 pressed!\n"; break; case 320: cout<<"F6 pressed!\n"; break; case 321: cout<<"F7 pressed!\n"; break; case 322: cout<<"F8 pressed!\n"; break; case 323: cout<<"F9 pressed!\n"; break; case 324: cout<<"F10 pressed!\n"; break; default: cout<<"Non function key was pressed!\n"; break; } } else cout<<"Non Function Key pressed!\n"; }
Real Eyes Realize Real Lies
My Resume
My Resume
Coloring your text
http://www.daniweb.com/techtalkforum...0122#post30122
File I/O
http://www.daniweb.com/techtalkforums/thread5720.html
http://www.daniweb.com/techtalkforum...0122#post30122
File I/O
http://www.daniweb.com/techtalkforums/thread5720.html
![]() |
Similar Threads
- system(" ") (C++)
- need good project of system sw (Java)
- how can I copy asp.net project from one system and work on it in a different system (ASP.NET)
Other Threads in the C++ Forum
- Previous Thread: To c++.NET
- Next Thread: help with an easy code
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets





