Annonceindlæg fra Barco
10. februar 2004 - 19:12
#1
gotoxy er ikke standard, så om du har og hvilken .h fil du skal inkludere afhænger af din compiler. Du kan prøve med: #include <conio.h>
10. februar 2004 - 21:10
#4
uha, det er den ikke glad for: gotoxy(10,10); cout << "Virker det?"; skriver følgende fejl error C2065: 'gotoxy' : undeclared identifier
10. februar 2004 - 21:22
#6
ahh har fået det til at virke nu :) oprettede bare min egen lille funktion. void gotoxy(int x, int y) { COORD coord; coord.X = x; coord.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); }
10. februar 2004 - 21:38
#8
Jeg lavede engang det her lille pussige stykke kode i.f.m. et spørgsmål: #include <time.h> #include <stdlib.h> #include <string.h> #include <windows.h> CRITICAL_SECTION cs; HANDLE console; void gotoxy(int x,int y) { COORD pos; pos.X = x; pos.Y = y; SetConsoleCursorPosition(console, pos); } void loop1() { char c[] = { '|', '/', '-', '\\', '|', '/', '-', '\\' }; int i = 0; while(true) { EnterCriticalSection(&cs); gotoxy(40,10); DWORD dummy; WriteConsole(console, &c[i % 8], 1, &dummy, NULL); LeaveCriticalSection(&cs); Sleep(1000); i++; } } void loop2() { while(true) { EnterCriticalSection(&cs); gotoxy(30,1); time_t t = time(NULL); DWORD dummy; char *s = ctime(&t); WriteConsole(console, s, strlen(s), &dummy, NULL); LeaveCriticalSection(&cs); Sleep(1000); } } DWORD __stdcall loop1dispatch(void *p) { loop1(); return 0; } DWORD __stdcall loop2dispatch(void *p) { loop2(); return 0; } void threadloop1() { DWORD id; CreateThread(NULL,0,loop1dispatch,NULL,0,&id); } void threadloop2() { DWORD id; CreateThread(NULL,0,loop2dispatch,NULL,0,&id); } int main() { system("CLS"); console = GetStdHandle(STD_OUTPUT_HANDLE); InitializeCriticalSection(&cs); threadloop2(); loop1(); return 0; }