eingabe in der consolen mitte
-
Folgendes:
Ich füge die datei(n) zu meinem Projekt hinzu.
Dann Drück ich [F9] und es gibt Diese Meldung aus:in Member Funktion `void ic::Console::setWndSize(int,int)`: "min" wurde nicht erklärt (nutze erst diese Funktion) [Build>Error]exe:*** [path/to/prjkt/ic.o
Benutze: Dev C++ version 4.9.9.2
-
Jetzt weiß ich wieder, volkard, warum ich damals min() nicht verwenden wollte. Damit ich DevC++-Kompatibilität erreiche
So, also zurück zum Thema. Du gehst in die Datei "ic.cpp" und fügst dort am Beginn (über den Includes) folgende Zeile ein:
#define min(a, b) (((a) < (b)) ? (a) : (b))
MfG SideWinder
-
Immer noch der selbe Error
-
Im schlimmsten Fall steht in dienem WinAPI-Port irgendwo "#undef min" ungeschützt drin, also versuch die oben gepostete Zeile unter den Includes anzubringen.
MfG SideWinder
-
hmm
neue funktionen wollen auch erklärt sein.
so weit ich verstehe fehlt dar noch code
Welche Daten gehören zu:string a = ?; string b = ?;
-
Daten, huh? Das was du hier siehst ist keine Funktion sondern ein Makro, es wird vom Präcompiler ersetzt. Das ist zwar unter C++ kein guter Programmierstil wird aber in der WinAPI (Die in C geschrieben ist) oftmals benützt. Da dir das in der WinAPI fehlt hab ich dir meine Version des Makros aus der WinAPI gegeben.
Schreibst du im Code nun:
min(5,4);
führt der Präcompiler eine Textersetzung durch und der Compiler sieht nur noch:
(((5) < (4)) ? (5) : (4))
Die vielen Klammern sind in diesem speziellen Fall unnötig, damit aber nichts passieren kann wenn man "min(5-4,3-2)" aufruft, sollte man sie unbedingt lassen
BTW: Funktioniert es jetzt? Die ganze IC unter deinem Compiler?
MfG SideWinder
-
Noch nicht ganz ...
"((void)5 ,4)" kann man nicht als Funktion nutzen
-
Zeile? min(5,4) wird doch nirgends aufgerufen, min wird doch in einem ganz anderem Kontext verwendet, du sollst nur die Zeile von vorher unter die Includes (in der ic.cpp!) schreiben, sonst nix
MfG SideWinder
-
bin halt a bisserl plan los ... sorry
-
namenlos schrieb:
bin halt a bisserl plan los ... sorry
Einfach genauer lesen
Funktionierts jetzt oder nicht?
MfG SideWinder
-
will aber immer noch a und b wissen
und meint Wörtlich in zeile 248(ich habs hoffentlich richtig plaziert):Each undeclared identifier is reported only once for each funktion it appears in
-
Zeig mal deine ic.cpp her, da stimmt ja was nicht
MfG SideWinder
-
///// Includes ///////////////////////////////////////////////////////////////// #include "ic.hpp" //////////////////////////////////////////////////////////////////////////////// #define min (a, a) (((a) < (b)) ? (a) : (b)) namespace ic { ///// Console ////////////////////////////////////////////////////////////// const COORD Console::origin = {0,0}; Console::Console () : hWnd(GetConsoleWindow()) , hConsoleOutput(GetStdHandle(STD_OUTPUT_HANDLE)) , wndBufMode(false) { HMODULE kernel32 = GetModuleHandle(TEXT("kernel32.dll")); SetConsoleDisplayMode = reinterpret_cast<SETCONSOLEDISPLAYMODE>(GetProcAddress(kernel32,"SetConsoleDisplayMode")); disableWndBufMode(); setWndPos(100,100); setWndSize(80,25); clear(); } Console::~Console () { enableWndBufMode(); } Console& Console::getInstance () { static Console instance; return instance; } void Console::hide () { ShowWindow(hWnd,SW_HIDE); } void Console::show () { ShowWindow(hWnd,SW_SHOW); } void Console::minimize () { ShowWindow(hWnd,SW_MINIMIZE); } void Console::maximize () { ShowWindow(hWnd,SW_MAXIMIZE); } void Console::restore () { ShowWindow(hWnd,SW_NORMAL); } void Console::clearColor (Color color) { DWORD attrsWritten; FillConsoleOutputAttribute(hConsoleOutput,color,getWndBufSizeX()*getWndBufSizeY(),origin,&attrsWritten); } void Console::clearText (TCHAR character) { DWORD charsWritten; FillConsoleOutputCharacter(hConsoleOutput,character,getWndBufSizeX()*getWndBufSizeY(),origin,&charsWritten); } void Console::clear (Color color, TCHAR character) { clearColor(color); clearText(character); } TextColor Console::getTextColor () const { return getTextColor(getCSBI().wAttributes); } void Console::setTextColor (TextColor color) { SetConsoleTextAttribute(hConsoleOutput,color|getBgColor()); } BgColor Console::getBgColor () const { return getBgColor(getCSBI().wAttributes); } void Console::setBgColor (BgColor color) { SetConsoleTextAttribute(hConsoleOutput,getTextColor()|color); } Color Console::getColor () const { return getCSBI().wAttributes; } void Console::setColor (Color color) { SetConsoleTextAttribute(hConsoleOutput,color); } int Console::getCurPosX () const { return getCSBI().dwCursorPosition.X; } int Console::getCurPosY () const { return getCSBI().dwCursorPosition.Y; } void Console::setCurPos (int x, int y) { COORD pos; pos.X = x; pos.Y = y; SetConsoleCursorPosition(hConsoleOutput,pos); } int Console::getCurSize () const { CONSOLE_CURSOR_INFO cci = getCCI(); if(!cci.bVisible) return 0; return cci.dwSize; } void Console::setCurSize (int size) { CONSOLE_CURSOR_INFO cci; if(size > 0) { cci.bVisible = TRUE; cci.dwSize = size; } else { cci.bVisible = FALSE; cci.dwSize = 100; } SetConsoleCursorInfo(hConsoleOutput,&cci); } bool Console::isWndBufMode () const { return wndBufMode; } void Console::enableWndBufMode () { SetConsoleMode(hConsoleOutput,ENABLE_PROCESSED_OUTPUT|ENABLE_WRAP_AT_EOL_OUTPUT); wndBufMode = true; } void Console::disableWndBufMode () { SetConsoleMode(hConsoleOutput,ENABLE_PROCESSED_OUTPUT); setWndBufSize(getWndSizeX()+1,getWndSizeY()+1); wndBufMode = false; } bool Console::isWndFSMode () const { DWORD flags; GetConsoleDisplayMode(&flags); return flags & CONSOLE_FULLSCREEN_MODE; } void Console::enableWndFSMode () { COORD newScreenBufferDimensions; SetConsoleDisplayMode(hConsoleOutput,CONSOLE_FULLSCREEN_MODE,&newScreenBufferDimensions); } void Console::disableWndFSMode () { COORD newScreenBufferDimensions; SetConsoleDisplayMode(hConsoleOutput,CONSOLE_WINDOWED_MODE,&newScreenBufferDimensions); } int Console::getWndPosX () const { RECT rect; GetWindowRect(hWnd,&rect); return rect.left; } int Console::getWndPosY () const { RECT rect; GetWindowRect(hWnd,&rect); return rect.top; } void Console::setWndPos (int x, int y) { SetWindowPos(hWnd,0,x,y,0,0,SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER); } int Console::getWndBufSizeX () const { return getCSBI().dwSize.X; } int Console::getWndBufSizeY () const { return getCSBI().dwSize.Y; } void Console::setWndBufSize (int x, int y) { if(!wndBufMode) return; COORD size; size.X = x; size.Y = y; SetConsoleScreenBufferSize(hConsoleOutput,size); } int Console::getWndSizeX () const { return getCSBI().srWindow.Right - getCSBI().srWindow.Left + 1; } int Console::getWndSizeY () const { return getCSBI().srWindow.Bottom - getCSBI().srWindow.Top + 1; } void Console::setWndSize (int x, int y) { min (5, 4) if(!wndBufMode) { zeroWndSize(); COORD bufSize; bufSize.X = min(x,getMaxWndSizeX()); bufSize.Y = min(y,getMaxWndSizeY()); SetConsoleScreenBufferSize(hConsoleOutput,bufSize); } SMALL_RECT wndSize; wndSize.Top = 0; wndSize.Left = 0; wndSize.Right = min(x,getMaxWndSizeX()) - 1; wndSize.Bottom = min(y,getMaxWndSizeY()) - 1; SetConsoleWindowInfo(hConsoleOutput,TRUE,&wndSize); } int Console::getMaxWndSizeX () const { return GetLargestConsoleWindowSize(hConsoleOutput).X; } int Console::getMaxWndSizeY () const { return GetLargestConsoleWindowSize(hConsoleOutput).Y; } std::basic_string<TCHAR> Console::getTitle () const { const int MAX_TITLE_LEN = 64 * 1024; TCHAR title [MAX_TITLE_LEN]; GetConsoleTitle(title,MAX_TITLE_LEN); return title; } void Console::setTitle (const std::basic_string<TCHAR>& title) { SetConsoleTitle(title.c_str()); } CONSOLE_CURSOR_INFO Console::getCCI () const { CONSOLE_CURSOR_INFO cci; GetConsoleCursorInfo(hConsoleOutput,&cci); return cci; } CONSOLE_SCREEN_BUFFER_INFO Console::getCSBI () const { CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo(hConsoleOutput,&csbi); return csbi; } void Console::zeroWndSize () { COORD bufSize; bufSize.X = 1; bufSize.Y = 1; SetConsoleScreenBufferSize(hConsoleOutput,bufSize); SMALL_RECT wndSize; wndSize.Top = 0; wndSize.Left = 0; wndSize.Right = 0; wndSize.Bottom = 0; SetConsoleWindowInfo(hConsoleOutput,TRUE,&wndSize); } Console& con = Console::getInstance(); //////////////////////////////////////////////////////////////////////////// }
-
#define min (a, a) (((a) < (b)) ? (a) : (b)) // Muss so heißen: #define min(a, b) (((a) < (b)) ? (a) : (b))
MfG SideWinder
-
Danke läuft
-
Wenn tatsächlich alles läuft, bring ich heute Abend noch eine DevCpp-Kompatible Version raus
MfG SideWinder
-
SideWinder schrieb:
Die Anfangsposition für einen String str der Länge len bekommst du die Koordinaten für den Beginn der Ausgabe über folgende Berechnungen:
string str = "Hello World"; int len = str.length(); int xbegin = (xges/2)-(len/2) int ybegin = (yges/2) gotoxy(xbegin,ybegin) cout << str;
Die unbekannten Variablen xges und yges und die fehlende Funktion gotoxy() kannst du mit Hilfe der Improved Console einbinden: http://ic.c-plusplus.net
MfG SideWinder
--------------------------------------------------------------------------------
und was kommt bei "xges" & "yges" rein ... sind nähmlich auch nicht erklärt
bzw: findet es der compimiler nicht.
-
xges ist con.getWndSizeX() und yges ist con.getWndSizeY()
MfG SideWinder
-
naja mit der ic hats nicht geklappt ....
aber dafür mit der conioex.hpp und conioex.cpp .
jetzt steht der cursor in der mitte unter einem textund ab den zeitpunkt war ich glücklich
Danke nochmals für den hilfe versuch mit der ic