简体   繁体   English

在c ++中,是否有可能/如何在输入后显示控制台输出,在同一行上,在给出用户输入之前?

[英]in c++, is it possible to / how can i display console output after input, on same line, before user's input is given?

In C++, when writing to and taking information from the console using cout / cin, is it possible to do something like 在C ++中,当使用cout / cin从控制台写入和获取信息时,是否可以执行类似的操作

ENTER YOUR DATA HERE --> __ <-- ENTER YOUR DATA HERE 在此输入您的数据 - > __ < - 在此输入您的数据

With the user input cursor where the underscores are located, and output located on either side of the cursor, and then the user's typed input appearing between those two bits of output before being returned to cin? 用户输入光标位于下划线所在的位置,并且输出位于光标的两侧,然后用户的输入输入出现在这两位输出之间,然后返回到cin?

If so how would I got about doing that? 如果是这样我将如何做到这一点?

I hope that between my title and explanation here that it's clear what I'm asking, if not I can try to explain further. 我希望在我的标题和解释之间明确我要问的是什么,如果不是,我可以尝试进一步解释。

Ideally I'd like to do this using iostream / cin & cout, because those are what I've used in the past. 理想情况下,我想使用iostream / cin和cout这样做,因为这些是我过去使用过的。 If the solution is to use... printf or similar I'll do that but may need a bit of additional explanation since I'm not really experienced in using that for output. 如果解决方案是使用... printf或类似的我会这样做,但可能需要一些额外的解释,因为我没有经验使用它输出。

NOTE: I tried to find an answer for this problem and I can't say for sure that there wasn't one, it was mostly just a matter of finding a huge amount of other input/output-related questions. 注意:我试图找到这个问题的答案,我不能确定没有一个,这主要是找到大量其他输入/输出相关的问题。

EDIT: This is using the DOS shell on Windows 7, compiling from the Windows Visual Studio 2012 command-line compiler. 编辑:这是在Windows 7上使用DOS shell,从Windows Visual Studio 2012命令行编译器编译。

If Windows, use the Console API. 如果是Windows,请使用Console API。 http://msdn.microsoft.com/en-us/library/windows/desktop/ms682073(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/windows/desktop/ms682073(v=vs.85).aspx

If Linux, use the curses library: http://en.wikipedia.org/wiki/Ncurses 如果是Linux,请使用curses库: http//en.wikipedia.org/wiki/Ncurses

If you are using windows you have the option to use the conio.h. 如果您使用的是Windows,则可以选择使用conio.h。

#include<iostream.h>
#include<conio.h>

int main()
{
    clrscr();
    gotoxy(5,3);
    cout<<"HELLO WORLD";
    gotoxy(60,10);
    cout<<"HELLO WORLD";
    gotoxy(35,20);
    cout<<"HELLO WORLD";
    getch();
    return 0;
}

If you wish to use ANSI libraries only, you can try to take a look at this discussion: http://www.cplusplus.com/forum/lounge/78225/ 如果您只想使用ANSI库,可以尝试查看以下讨论: http//www.cplusplus.com/forum/lounge/78225/

In both cases all you have to do is print the first text, then use gotoxy, then you print seconde text, gotoxy again where you want the input to happens, and read the user input. 在这两种情况下,你所要做的就是打印第一个文本,然后使用gotoxy,然后再打印seconde文本,gotoxy,你想要输入的位置,并读取用户输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当用户在 C++ 的同一行中输入字符串和整数时,如何拆分字符串和整数? - How can I split string and integer when user input both the string and the integer in the same line in C++? 如何在 C++ 中以不同的方式接受来自同一行的用户输入? - How can I accept user input differently from the same line in C++? 如何在同一行C ++上输入多个变量 - How can I input multiple variables on the same line C++ 如何解决 output 控制台在输入或在 Visual Studio-2013 中编译 C++ 后消失的问题? - How can I overcome the issue of output console disappearing after taking input or compiling in Visual Studio-2013 for C++? C++ 如何暂停控制台 output 以便用户在继续之前可以阅读信息 - C++ How do I pause the console output so that the user can read info before continuing 如何在C ++控制台应用程序中将输入与输出分开? 我可以有两个光标吗? - How do I separate input from output in a C++ console application? Can I have two cursors? 如何在与用户输入相同的位置提示? C ++ - How to cout on same line as user input? C++ C++ 输入和 output 同时到控制台 window - C++ Input and output to the console window at the same time 如何将用户输入的格式设置为整齐的表格,以便在C ++中输出 - How can I format user input into a neat table for output in C++ 如何在C++中的同一行上输入? - How to take input on same line in c++?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM