Jump to content

  • Log In with Google      Sign In   
  • Create Account

std::cin question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Amnesty2   Members   -  Reputation: 203

Like
0Likes
Like

Posted 18 September 2013 - 10:52 PM

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?

 

 

 



Sponsor:

#2 Álvaro   Crossbones+   -  Reputation: 13368

Like
3Likes
Like

Posted 18 September 2013 - 11:48 PM

No, there is no platform-independent way of capturing individual keystrokes in C++.

#3 Bacterius   Crossbones+   -  Reputation: 8945

Like
0Likes
Like

Posted 19 September 2013 - 03:51 AM

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.


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#4 Tispe   Members   -  Reputation: 1037

Like
-1Likes
Like

Posted 19 September 2013 - 05:15 AM

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, 19 September 2013 - 05:27 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS