+ 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
10 Réponses
+ 12
Rahul Sahni
Thank you again
is there a way to just clear one word not all of screen?
+ 11
Hatsy Rei
i use visual studio 2017 but when i use
cout<<"\b";
it do nothing
+ 10
Rahul Sahni Thank you but i don't know C
+ 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.
+ 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
+ 4
clrscr();
OR
system("cls");
+ 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
+ 2
Maybe there exist some way but i don't know. sorry...
+ 2
i think sololearn compiler can't to this the way we want it to do because it takes input before execution.
+ 1
how do I do this in the sololearn compiler