help printing to the same pos with c++
I am trying to print to the same postion every time
example
i want to print 1 then print 2 were one is
does any one know how I would do that in c++ under dos?
thanks
You'll find more information here.
You'll have to get the Standard Output Handle, and then you can use it to position the Cursor (that blinking thingee).
An easy example that should work:
You'll have to get the Standard Output Handle, and then you can use it to position the Cursor (that blinking thingee).
An easy example that should work:
#include <windows.h>int main(){ HANDLE hOut; COORD co; hOut = GetStdHandle( STD_OUTPUT_HANDLE ); co.X = co.Y = 5; if( hOut != INVALID_HANDLE_VALUE ) { SetConsoleCursorPosition( hOut, co ); cout << "Hello!"; } return 0;}
this is how I did it
std::cout<< y<<"%";
std::cout<<"\b";std::cout<<"\b";std::cout<<"\b";std::cout<<"\b";
is there a way to make the cursor disaper tell I want it?
std::cout<< y<<"%";
std::cout<<"\b";std::cout<<"\b";std::cout<<"\b";std::cout<<"\b";
is there a way to make the cursor disaper tell I want it?
See my previous post (I edited it) for an example on how to place the cursor.
'\b' means backspace. '\r' goes back to the beginning of the line (but doesn't erase anything while going back).
'\b' means backspace. '\r' goes back to the beginning of the line (but doesn't erase anything while going back).
ARe you talking about simple text file processing, where you want to overwrite what you've previously placed?
The easiest way would probably be to reset your filestream pointer with seekg(). If you are going back one place, then you are moving backwards by one byte (one char...assuming non-unicode). So you can do something like this:
When you open the Sample.txt file, all you should see is "1".
The easiest way would probably be to reset your filestream pointer with seekg(). If you are going back one place, then you are moving backwards by one byte (one char...assuming non-unicode). So you can do something like this:
#include <fstream>int main(){ofstream outfile;outfile.open("Sample.txt")long pis; //position in stream. Used to indicate where you are//write the first characteroutfile << "2";pis = outfile.tellp(); //where you currently are in the streamoutfile.seek(pis-1); //move backwards one characteroutfile << "1"; //should overwrite the 2outfile.close();return 0;}
When you open the Sample.txt file, all you should see is "1".
Quote:Original post by kingpinzs
does any one know how I would do that in c++ under dos?
Under DOS, you load the ANSI.SYS driver and use the VT control codes.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement