i need a screen string changer:
cout << "Hello World!";
will result this :
Hello World!
but i need to change the Hello World to I'm Alive(just a example)
how to do that ?
Not 100% sure what you mean, but if you wanted to change output during runtime you can store a name or something in a variable and output its contents like this..
string i = "unknown";
while (1<2){
system("cls");
cin >> i;
cout << i << endl;
}
is the WAY but i not make exactly this is more complexy.
i make a Menu, this menu is to change the "Name" of a string pressing Enter, left, right.
but, is flicking, because then write and clean.
how to fix ?
i can't make the program wait one second, i make a menu and i want, This menu to be very proximity to real time.
and i tryed to make wih 200 not work :(
i think i'll overwrite the text, but how i do that ?
#include <iostream>
#include <windows.h>
#include <stdio.h>
usingnamespace std;
static HANDLE hout;
void GetReady()
{
hout= GetStdHandle(STD_OUTPUT_HANDLE);//Get the handle of the standard output
return;
}
void gotoxy(unsigned x,unsigned y)//Set cursor Position
{
COORD pos;
pos.X=x;
pos.Y=y;
SetConsoleCursorPosition(hout,pos);
return;
}
int main()
{
GetReady();
cout<<"Hello, World!";
system("pause");//Without pause, the program will run too fast for user to see clearly
gotoxy(0,0);//Return cursor to up-left corner
//Well, maybe I shoud clean the screen first to make sure no words is uncovered. But here the second sentence is longer than the first, and can cover the first completely.
cout<<"I'm a Chinese.";
system("pause");
return 0;
}
By the way, you turely can use system("cls") instead of my function, but you forgot to use system("pause") , and your program cleaned the screen before you saw it clearly.
What's more, you can usewhile(1) or while(ture) instead of while(1<2). while(1<2) will make others baffled.
yep is a scroll menu.
ok but there is a problem, i used a while and the "way" of you suggested,
therefore my program is writing all the screen, example :
hello!
hello!
hello!
hello!
...
but now dont flicking but is writing in my entire screen.
EDIT:
i have an idea now, how i can change a text foreground to black ?
if is another color i can use :
SetConsoleTextAttribute(hConsole, FOREGROUND_ ...
but isn't, how can i do this ?
i don't want the words flicking !
and, using the example up, is writing im my entire screen, but, if i put a system("cls") back to flick :(
Why it is writing in your entire screen? It only changes the first line.
Well, please describe what you want in detail.
ex. print "Hello, world!" on first line and then change it into "I'm I'm Alive" without flicking after press any key.
On my computer, this code works well. I just don't know what