clear string from the screen.

i want to do this.
1
2
3
4
5
6
7
8
9
10
11
12
13
#include<iostream>
#include<string.h>

using namespace std;

int main()
{
      string str="i have itchy....";
      stirng str2="balls.";
      cout<<str1<<endl;
      cout<<str2;
      return 0;
}


will output on the screen...
1
2
i have itchy.... 
balls.


so i just want to erase my "balls" form the screen and put something else.
Here's the deal...

If you absolutely need to stick to platform independent ISO standard C/C++, you are out of luck.

If you are working with Windows and are willing to use Win Api functions, then you are in luck.

Which?
i am working in windows.
btw i would like to know every possible way to do this currently not doing any important thing.
Here's a little program I made for you. Hope it helps. There are piles of Win Api functions for doing everything imaginable with console windows...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <windows.h>
#include <stdio.h>

void cls(HANDLE hStdOutput)
{
 COORD coordScreen = {0,0};
 DWORD cCharsWritten;
 CONSOLE_SCREEN_BUFFER_INFO csbi;
 DWORD dwConSize;

 GetConsoleScreenBufferInfo(hStdOutput, &csbi);
 dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
 FillConsoleOutputCharacter(hStdOutput,(TCHAR)' ',dwConSize,coordScreen,&cCharsWritten);
 GetConsoleScreenBufferInfo(hStdOutput,&csbi);
 FillConsoleOutputAttribute(hStdOutput,csbi.wAttributes,dwConSize, coordScreen,&cCharsWritten);
 SetConsoleCursorPosition(hStdOutput,coordScreen);
}

int main()
{
 HANDLE hStdOutput;
 COORD cd;

 hStdOutput=GetStdHandle(STD_OUTPUT_HANDLE);
 printf("I've Got Itchy....\n");
 printf("...balls!\n");
 printf("\n\npress any key to continue....\n");
 getchar();
 cd.X=0, cd.Y=1;
 SetConsoleCursorPosition(hStdOutput,cd);
 printf("....feet!\n");
 printf("\n\npress any key to continue....\n");
 getchar();
 printf("\nWill Now Clear Screen!\n");
 printf("\n\npress any key to continue....\n");
 getchar();
 cls(hStdOutput);

 return 0;
}


If you want to know about mouse stuff, let me know...

I think i should learn some windows API some of the piece of codes are never seen by my eyes.

well i will learn it.

and about the mouse thing is it possible to point to string and clear it?
i am creating a simple console application so if i can do point and click thing in console window that would be something new for me.

and about the mouse thing is it possible to point to string and clear it?


yes, you must track the mouse, and you have to know the x/y coordinates of a string you want to clear.
Topic archived. No new replies allowed.