Jump to content
  • Advertisement
Sign in to follow this  
Amnesty2

std::cin question

This topic is 2126 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'll give an example because i don't really know how to word it.

 

cout << "Input a filename :";

cin >> file;

 

I would like to print

Input a filename :autosave.txt_<cursor here>
autosave.txt can be backspaced on and edited.

 

I'd like to put some stuff in cins buffer before i ask and have it displayed and be editable. 

 

i can only think of platform specific ways of achieving something similar.

Simulating key presses or rolling your input function that pops data off on backspace, pushes chars in, and sets the cursor position accordingly.

 

I know, iostreams let you hack around at a pretty low level with them so i assume this possible some how. Maybe?

 

 

 

Share this post


Link to post
Share on other sites
Advertisement

As Alvaro says, there is no standard way of doing this. But ncurses (and its Windows port PDCurses) abstracts a lot of terminal-specific functionality under a cross-platform API which should work on a wide enough range of systems. Perhaps you could take a look and see if it meets your needs.

Share this post


Link to post
Share on other sites

You can edit the last line by using '\r' in the printf() function.

 

like this :

const int NumDots = 65;
char s[100];
int xpos = 0;

sprintf_s(s, "X.......................................................................");

while(true){  

if(xpos>NumDots){
s[xpos] = '.'; 
xpos = 0;
s[xpos] = 'X';
 
} else {
xpos++;
s[xpos] = 'X';
s[xpos-1] = '.';
}
 Sleep(50);
                 
printf("%s\r", s);		//updates last line
} 
Edited by Tispe

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!