CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2011
    Location
    Orange County, CA
    Posts
    82

    Question Quick O/I Question

    is it possible to ask a question, but display the cursor above said question?

    for example:
    Code:
          cout << "5 / 25 = ";
          cin >> answer;
    in the code snippet above, the cursor will appear one space after the = sign, but i want it to appear above the 5 / 25, is this possible?
    -and if so, how?

  2. #2
    Join Date
    May 2009
    Location
    Boston
    Posts
    375

    Re: Quick O/I Question

    I would say that's not possible in a shell. The shell will always print output and then return below for the next instruction. I don't see any way to achieve that behavior without writing your own interface.

    Is there some urgent need to have the prompt appear above the text, or is this just aesthetic? Maybe you could tweak the shell to print from the bottom of the page up, or something like that.

    LMHmedchem

  3. #3
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: Quick O/I Question

    From a strict C/C++ point of view, there is no shell, or terminal, or anything. There is just an "input stream" and an "output stream" (and log/err).

    On windows/unix PCs, these streams are usually associated to a console, but that is the OS's choice.

    To do what you want, you'll need an external library that can interface with your OS/console.

    windows.h is a good place to start if you are on windows. I've heard conio is also good for simple command formating.

    If your objective is to learn C++, then I wouldn't bother though. Output formatting is one of the less interesting, aspects of C++, and will bring you very little knowledge on the language.
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Quick O/I Question

    If this is for Windows, <conio.h> won't help; it doesn't provide this capability. But the Windows Console API, in particular SetConsoleCursorPostion(), does. However this is even less C++-ish than <conio.h> because it's Windows API instead of C runtime library functions.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  5. #5
    Join Date
    Jan 2011
    Location
    Orange County, CA
    Posts
    82

    Re: Quick O/I Question

    alright then, thanks guys, just wondering if there was a quick command or something, but if i need to mess with a interface, then i dont need it that much...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured