"Textformatierung" in C++
-
Hi,
ich möchte meine "alten" Konsole-Programme
ein bisschen aufpeppen
Deshalb wollte ich euch fragen, was man außerendlnoch alles an
coutübergeben kann.
Ich würde z.B. gerne eine alte Ausgabe löschen oder wenigstens
die Konsole "clearen",
außerdem würde ich gerne die Hintergrundfarbe und die Schriftfarbe
ändern.Danke schonmal,
Grüße
-
C++ stellt dir da eher wenig zu Verfügung, im wesentlichen die Inhalte der <iomanip>. Wenn dir das nicht reicht, dann kannst du natürlich selbst noch Manipulatoren schreiben. Für Sachen wie Farben wirst du aber auf APIs bzw. Steuercodes zurückgreifen müssen, die speziell für deine Ziel-Konsole existieren. Mit Standard-C++ wird sich da eher wenig machen lassen.
-
Hmmm,
ich denk so an Konsolen im "Matrix-Style" und so ^^
und dass wie manchmal im Filmen die Buchstaben erst durch ein raster gehenmyPrint("cbc"); output: a <- Clearscreen b <- Clearscreen c <- Clearscreen ca <- Clearscreen cb <- Clearscreen cba <- Clearscreen cbb <- Clearscreen cbcAlso dass die Buchstaben so "runterklappen",
hab das mit Style oft schon gesehen (ich glaub sind oft VisualBasic Programme :D)
wie machen die das denn?
Aber danke schonmal für die Auskunft
-
Streams kann man z.B. mit folgenden Funktionen manipulieren
für eine formatierte Ausgabe.std::fstream fout;
...
fout.fill(' ');
fout.width(12);
fout.precision(2);
fout.setf(std::ios::right, std::ios::adjustfield);
fout.flags(std::ios::fixed);Hier die Hilfe der MSDN
Viel Spaß,
As the iostream class hierarchy diagram shows, ios is the base class for all the input/output stream classes. While ios is not technically an abstract base class, you will not usually construct ios objects, nor will you derive classes directly from ios. Instead, you will use the derived classes istream and ostream or other derived classes.
Even though you will not use ios directly, you will be using many of the inherited member functions and data members described here. Remember that these inherited member function descriptions are not duplicated for derived classes.
Data Members (static) — Public Members
basefield
Mask for obtaining the conversion base flags (dec, oct, or hex).
adjustfield
Mask for obtaining the field padding flags (left, right, or internal).
floatfield
Mask for obtaining the numeric format (scientific or fixed).
Construction/Destruction — Public Members
ios
Constructor for use in derived classes.
~ios
Virtual destructor.
Flag and Format Access Functions — Public Members
flags
Sets or reads the stream’s format flags.
setf
Manipulates the stream’s format flags.
unsetf
Clears the stream’s format flags.
fill
Sets or reads the stream’s fill character.
precision
Sets or reads the stream’s floating-point format display precision.
width
Sets or reads the stream’s output field width.
Status-Testing Functions — Public Members
good
Indicates good stream status.
bad
Indicates a serious I/O error.
eof
Indicates end of file.
fail
Indicates a serious I/O error or a possibly recoverable I/O formatting error.
rdstate
Returns the stream’s error flags.
clear
Sets or clears the stream’s error flags.
User-Defined Format Flags — Public Members
bitalloc
Provides a mask for an unused format bit in the stream’s private flags variable (static function).
xalloc
Provides an index to an unused word in an array reserved for special-purpose stream state variables (static function).
iword
Converts the index provided by xalloc to a reference (valid only until the next xalloc).
pword
Converts the index provided by xalloc to a pointer (valid only until the next xalloc).
Other Functions — Public Members
delbuf
Controls the connection of streambuf deletion with ios destruction.
rdbuf
Gets the stream’s streambuf object.
sync_with_stdio
Synchronizes the predefined objects cin, cout, cerr, and clog with the standard I/O system.
tie
Ties a specified ostream to this stream.
Operators — Public Members
operator void*
Converts a stream to a pointer that can be used only for error checking.
operator !
Returns a nonzero value if a stream I/O error occurs.
ios Manipulators
dec
Causes the interpretation of subsequent fields in decimal format (the default mode).
hex
Causes the interpretation of subsequent fields in hexadecimal format.
oct
Causes the interpretation of subsequent fields in octal format.
binary
Sets the stream’s mode to binary (stream must have an associated filebuf buffer).
text
Sets the stream’s mode to text, the default mode (stream must have an associated filebuf buffer).
Parameterized Manipulators
(#include <iomanip.h> required)
setiosflags
Sets the stream’s format flags.
resetiosflags
Resets the stream’s format flags.
setfill
Sets the stream’s fill character.
setprecision
Sets the stream’s floating-point display precision.
setw
Sets the stream’s field width (for the next field only).
Abstract Stream Base Class
See Also istream, ostream
-
Hallo
@ schokomann : Beim nächsten Mal reicht ein Link auf die Seite aus der MSDN.
Aber wie Meister schon gesagt, kann Standard-C++ zum Beispiel Farben nicht, das geht nur mit zusätzlichen plattformspezifischen Mitteln. Schau in die Konsolen-FAQ hier im Forum, da gibts einen Thread zur Improved Console.bis bald
akari
-
ja, mache ich.
Ich habe mich auch verlesen. Ich war der Meinung die Ausgabe sollte
formatiert sein.
-
akari schrieb:
Hallo
@ schokomann : Beim nächsten Mal reicht ein Link auf die Seite aus der MSDN.
Aber wie Meister schon gesagt, kann Standard-C++ zum Beispiel Farben nicht, das geht nur mit zusätzlichen plattformspezifischen Mitteln. Schau in die Konsolen-FAQ hier im Forum, da gibts einen Thread zur Improved Console.bis bald
akariOk Danke und auch danke an schokomann,
bin jetzt dank euch auf dem "aktuellen" Stand
-
Hallo
Schau doch mal ins Consolenforum und dort genau bei der Improved Console. Mit der kann man genau das machen, was du willst.
chrische