+ 12

Remove printed text in console application

i wonna write a program in c++ console application , for example it ask a question from user and when user input the answer , it remove question (or even user's input) words i hear about "\b" and "\r" to remove characters but they don't do like i want

24th Jun 2018, 12:42 PM
AliR૯za
AliR૯za - avatar
10 Antworten
+ 12
Rahul Sahni Thank you again is there a way to just clear one word not all of screen?
24th Jun 2018, 3:13 PM
AliR૯za
AliR૯za - avatar
+ 11
Hatsy Rei i use visual studio 2017 but when i use cout<<"\b"; it do nothing
24th Jun 2018, 5:53 PM
AliR૯za
AliR૯za - avatar
+ 10
Rahul Sahni Thank you but i don't know C
24th Jun 2018, 2:35 PM
AliR૯za
AliR૯za - avatar
+ 5
#include<stdio.h> int main() { int i; char ch; for(i=0;i<10;i++) printf("Hello world\n"); printf("\n\n\nEnter:\n C To clear the Console text. \n E To exit the Console.\n"); scanf("%c",&ch); if (ch=='c' || ch=='C') system("cls"); else if (ch=='e' || ch=='E') exit(0); } --------------------------------- I Hope it helps.
24th Jun 2018, 1:13 PM
Rahul Sahani
Rahul Sahani - avatar
+ 4
And before you dig straight into the answers provided, remember that system() calls should be avoided for reasons. http://www.cplusplus.com/forum/articles/11153/ https://wiki.sei.cmu.edu/confluence/plugins/servlet/mobile?contentId=87152177#content/view/87152177 Regarding you question: It really depends on the console that you are dealing with. You can, for instance, use escape characters to move the cursor backwards, write whitespaces to "erase" the printed characters and then move the cursor backwards again. Again, it won't work on SL. Have you checked this thread? https://stackoverflow.com/questions/13440272/how-to-delete-an-already-written-character-in-c-console/13440321
24th Jun 2018, 5:12 PM
Hatsy Rei
Hatsy Rei - avatar
+ 4
clrscr(); OR system("cls");
26th Jun 2018, 2:21 PM
Shahil Ahmed
Shahil Ahmed - avatar
+ 2
#include<iostream> using namespace std; int main() { int i; char ch; for(i=0;i<10;i++) cout<<"Hello world"; cout<<"\n\n\nEnter :\n C To clear Console.\n E To Exit."; cin>>ch; if (ch=='c' || ch== 'C') system("cls"); else if(ch=='e' || ch=='E') exit(0); return 0; } ----------------------------------------- For - ● Windows - use cls ● linux - use clear
24th Jun 2018, 3:06 PM
Rahul Sahani
Rahul Sahani - avatar
+ 2
Maybe there exist some way but i don't know. sorry...
24th Jun 2018, 3:52 PM
Rahul Sahani
Rahul Sahani - avatar
+ 2
i think sololearn compiler can't to this the way we want it to do because it takes input before execution.
24th Jun 2018, 4:50 PM
Rahul Sahani
Rahul Sahani - avatar
+ 1
how do I do this in the sololearn compiler
24th Jun 2018, 4:39 PM
Cesar Eduardo Lezano
Cesar Eduardo Lezano - avatar