Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I need to "delete" a ENTER character that I,ve writeen in the console with C++.
in BorlandC I have gotoxy, wherex, wherey, movetetxt and so on. But I work in Visual C by Microsoft. how can I move un a line (by deleting a '\n',or however?

I don't believe VC supports console modes in terms of character control anymore, so you'd most likely need the use the WINAPI for things like cursor position, but I'm not familiar with the API.
You might give ungetc (stdio.h) a try, but it won't remove an EOF character. There is also putback (iostream) which works on the last character in the current stream.
Post your code, so others might get an idea of what you're trying to do.
HTH

MSDN Library Visual Studio 6.0
Active Subset: Visual C++, Platform SDK and Win CE Docs
Search for: Console Functions
Look at these topics:
Topic: Console Functions
Topic: Console: Demonstration of the Console Functions=================================================
Here is an example using Console Functions
test_console.cpp
----------------
#include <windows.h>
#include "console.h"int main()
{
HANDLE hConsole;
BOOL bSuccess;
char *buffer="Hello World", c;hConsole = InitConsole();
cls(hConsole);
bSuccess = SetConsoleCursorPosition(hConsole, 12, 40);
bSuccess = PutConsoleString(hConsole, buffer);
bSuccess = SetConsoleCursorPosition(hConsole, 10, 30);
bSuccess = PutConsoleString(hConsole, "Up 2 lines");
c = GetConsoleChar();
return 0;
}console.h
---------
#define BACKGROUND_WHITE (WORD) 0x00f0
#define FOREGROUND_BLACK (WORD) 0x0000
HANDLE InitConsole();
void cls(HANDLE hConsole);
BOOL SetConsoleCursorPosition(HANDLE hConsole, int row, int col);
int PutConsoleString(HANDLE hConsole, char *s);
CHAR GetConsoleChar(void);console.cpp
-----------
#include <windows.h>
#include "console.h"HANDLE InitConsole()
{
HANDLE hConsole;
BOOL bSuccess;
hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
bSuccess = SetConsoleActiveScreenBuffer(hConsole);
bSuccess = SetConsoleTextAttribute(hConsole, BACKGROUND_WHITE |
FOREGROUND_BLACK);
return hConsole;
}
void cls(HANDLE hConsole)
{
COORD coordScreen = { 0, 0 }; /* here's where we'll home the cursor */
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
DWORD dwConSize; /* number of character cells in the current buffer */
bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
bSuccess = FillConsoleOutputCharacter(hConsole, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten);
bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi);
bSuccess = FillConsoleOutputAttribute(hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten);
bSuccess = SetConsoleCursorPosition(hConsole, coordScreen);
return;
}BOOL SetConsoleCursorPosition(HANDLE hConsole, int row, int col)
{
BOOL bSuccess;
COORD p;
p.X=col;
p.Y=row;
bSuccess = SetConsoleCursorPosition(hConsole, p);
return bSuccess;
}BOOL PutConsoleString(HANDLE hConsole, PCHAR s)
{
BOOL bSuccess;
DWORD cCharsWritten;
BOOL retflag = TRUE;
bSuccess = WriteConsole(hConsole, s, strlen(s), &cCharsWritten, NULL);
if (bSuccess)
retflag = bSuccess;
else
retflag = FALSE;
return(retflag);
}BOOL PutConsoleLine(HANDLE hConsole, PCHAR s)
{
BOOL bSuccess;
const PCHAR crlf = "\n";
BOOL retflag = TRUE;
bSuccess = PutConsoleString(hConsole, s);
if (bSuccess)
bSuccess = PutConsoleString(hConsole, crlf);
if (bSuccess)
retflag = bSuccess;
else
retflag = FALSE;
return(retflag);
}CHAR GetConsoleChar(void)
{
HANDLE hStdIn; /* standard input */
DWORD dwInputMode; /* to save the input mode */
BOOL bSuccess;
CHAR chBuf; /* buffer to read into */
DWORD dwRead;hStdIn = GetStdHandle(STD_INPUT_HANDLE);
bSuccess = GetConsoleMode(hStdIn, &dwInputMode);
bSuccess = SetConsoleMode(hStdIn, dwInputMode & ~ENABLE_LINE_INPUT &
~ENABLE_ECHO_INPUT);
bSuccess = ReadFile(hStdIn, &chBuf, sizeof(chBuf), &dwRead, NULL);
bSuccess = SetConsoleMode(hStdIn, dwInputMode);
return(chBuf);
}

egkenny,
Is that portable to other compilers like Dec-C or Code Warrior 5 or is it VC specific? I'd sure like to try it :)

![]() |
Re mysql/php
|
Hiding Tasks in Task Mana...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |