Jump to content
  • Advertisement
Sign in to follow this  
kingpinzs

help printing to the same pos with c++

This topic is 5047 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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:
#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;
}

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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:



#include <fstream>

int main()
{
ofstream outfile;
outfile.open("Sample.txt")
long pis; //position in stream. Used to indicate where you are

//write the first character
outfile << "2";
pis = outfile.tellp(); //where you currently are in the stream
outfile.seek(pis-1); //move backwards one character
outfile << "1"; //should overwrite the 2
outfile.close();

return 0;
}


When you open the Sample.txt file, all you should see is "1".

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!