I am trying to delete string from cmd but not all that is printed(cout)just that string is that possible to do?
1 2 3 4 5 6 7 8 9 10 11 12 13
cout << "TTTTTTT" << endl; //for example
/*
Now i cin string (str) and when i cin it and click enter can somehow str be deleted from cmd
*/
string str;
cin >> str;
cout << str;
// Now here some command that will delete that str that was printed in my cmd.
// Not system("Clear"); because it would delete everything i already printed
You should be able to print '\r' to move the cursor to the beginning of the line in a console, such that you can overwrite what was already printed on that line. A sequence of backspace characters '\b' can also be used to move the cursor back toward the beginning of a line, one character at a time.
Otherwise, if you're trying to do something more complex than that, that's beyond the scope of what C++'s standard I/O is supposed to accomplish. For that, you'll need to look into a proper library for manipulating the console, be it Windows's Console API, ncurses, or something else. You'd then use that instead of the stuff in <iostream>.
there are libraries to do console output in colors and to jump the location of the cursor and so on as well. anyone can use ncurses and windows has gotoxy(x,y) and some other handy ones.
Nope. Maybe it's possible but some system calls are needed beforehand to make it compatible?
Either way I'd just use something like ncurses instead of abusing stdout streams.
(I used MinGW btw)
Edit: LOL, if I run that in PowerShell it brings up the Mouse Properties menu. Haha what?
Doesn't Windows have two command prompts terminal emulators as of June, one of which is the POS that Windows has always had, and the other is actually sane?
In 2016, Microsoft released the Windows 10 Version 1511 update which unexpectedly implemented support for ANSI escape sequences[12]. The change was designed to complement the Windows Subsystem for Linux, adding to the Windows Console Host used by Command Prompt support for character escape codes used by terminal-based software for Unix-like systems. This is not the default behavior and must be enabled by enabled programmatically with the Win32 API via SetConsoleMode(handle, ENABLE_VIRTUAL_TERMINAL_PROCESSING).[13] This was enabled by CMD.EXE but not initially by PowerShell[14] however, Windows PowerShell 5.1 now enables this by default.
I have yet to try it, but it promises full Unicode support, among other things. It must be downloaded from the Windows Store (or compiled from github sources).
As for OP’s problem, he is making a design mistake. The correct answer is don’t do that. Figure out a better way of making your program run.
If you are interested in basic terminal functionality on Windows and Linux, take a look at the example here, which will get you started with basics: (Game of Live:Gosper Glider Gun|http://www.cplusplus.com/forum/lounge/75168/)
I am not sure when this change was actually implemented. As you know, Microsoft wants to pretend that there is only One Windows and their most recent documentation has been lax in supplying minimum system requirements for stuff.
But, you shouldn’t be using terminal escape sequences to control the Windows Console from your programs anyway. I suspect, though uninformed (because I don’t care), that the introduction of escape sequence handling in the Windows Console has to do with the ongoing *nix/POSIX integration.