0

In c++, by default input is taken as left align. I am looking to write a function or code to take the input string as right align. Means, my input cursor will be at the right side of the prompt/textbox. can anyone help me in this regard? Here is the screenshot of my requirement:

Right aligned input cursor

Edited:
I have actually 2 problem... Is there any way to take input(cin) right aligned (above picture)?

if not then can you provide me with the code to make right align input textbox in visual c++ ?

Muhaimenul Islam
  • 747
  • 1
  • 7
  • 22
  • C++ doesn't have textboxes or aligned input. Can you please elaborate? Also please read [the help pages](http://stackoverflow.com/help), especially ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). Also please [take the SO tour](http://stackoverflow.com/tour) and [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask). Lastly please learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). – Some programmer dude Dec 11 '17 at 07:44
  • 1
    Possible duplicate of [How to Align text to the right using cout?](https://stackoverflow.com/questions/43033802/how-to-align-text-to-the-right-using-cout) – msc Dec 11 '17 at 07:45
  • I have actually 2 problem... Is there any way to take input(cin) right aligned? if not then can you provide me with the code to make right align input textbox in visual c++ ? – Muhaimenul Islam Dec 11 '17 at 07:53
  • This is more an OS issue than a language issue. Which OS are you working with, and which GUI? – Richard Hodges Dec 11 '17 at 07:56
  • When you say "right aligned", do you mean you want to read the input from right to left (instead of the normal left to right)? *Why* do you want to do that? What is the *actual* problem you want to solve by doing that? Perhaps you should read [about the XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) as well, and think about how it relates to your question? And by "textbox", do you mean the console window, using normal `std::cin` to read? Or do you have a GUI and want to read from a WIN32 control? – Some programmer dude Dec 11 '17 at 07:56
  • Windows OS. Using Codeblocks IDE for normal input(cin). And for visual input (textbox), I am using visual studio. – Muhaimenul Islam Dec 11 '17 at 07:57
  • Yes, I want to read the input from right to left (instead of the normal left to right).. I need to do that for academic purpose. This is the actual problem... "Take input from right aligned"... If there is no better way for console input..is there any way in visual c++ for input textbox? Standard console or Visual textbox, any way is appreciable. @Some Programmer Dude – Muhaimenul Islam Dec 11 '17 at 08:00
  • @TahmidSaim Why do you need to write a program to do this? Doesn't your OS have some sort of internationalization settings to allow right-to-left input? How do persons in countries that have right-to-left text use computers? – PaulMcKenzie Dec 11 '17 at 08:05
  • This is task I have to perform for my academic purpose. The task is to "write a function or code to take input from right aligned" .. If there is no better way for standard input console (cin), then any process for visual c++ textbox is also applicable. – Muhaimenul Islam Dec 11 '17 at 08:07
  • Will your input be "[space space space] abcdef"? Will your input be a file which is formatted in right to left alignment (with spaces padded at the beginning) or you are expected to make the cursor move from right to left? – Yashas Dec 11 '17 at 08:08
  • @Yashas, You got my point.... I have thought about "[space space space] abcdef" type solution. But actually I am looking for any process to make the cursor move from right to left. – Muhaimenul Islam Dec 11 '17 at 08:11
  • So that's is what you want. You should update your question title and description. You just had to ask "how to move the console cursor from right to left as input is given". As it is now, it is difficult to understand. – Yashas Dec 11 '17 at 08:12
  • I cant edit the post. but the titile should be as you have said, "how to move the console cursor from right to left as input is given" – Muhaimenul Islam Dec 11 '17 at 08:40

1 Answers1

0

Your question is too vague and broad to give an actual concise answer. However from what I'm gathering from your question as well as the comments listed below it, it appears that you are working with Windows and are tasked with writing a win32 console application where you have to manipulate the console to accept input that is right aligned.

What I can do for you here is point you in a direction that may give you the answers you are looking for. You can find the documentations for the Windows Console API here: https://learn.microsoft.com/en-us/windows/console/ There is quite a bit of information about everything you need to know on how to acquire a handle to the console, to getting the console buffer, info structures etc. How to manipulate the buffer size, the cursor position, changing font type, size & color(foreground, background and highlighted text). Other than that I will have to agree with the rest of the community that your initial question was too vague and broad and that it has the impression of a X/Y problem.

Francis Cugler
  • 7,788
  • 2
  • 28
  • 59