简体   繁体   English

当我使用Ctrl-C终止输入时,Visual Studio 2013中的输出减少了

[英]When I use Ctrl-C to terminate the input , the output is reduced in visual studio 2013

//Program to terminate the input by ctrl-c    
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main()
{
    vector<string> vec;
    string word;

    while (cin >> word)
        vec.push_back(word);

    cout << endl << endl;
    auto beg = vec.begin();
    while (beg != vec.end())
    {
        //to print the vector
        cout << *beg << endl;
        beg++;
    }
}

When in press control-c to terminate the input stream of... 在按Ctrl-c来终止...的输入流时

ankur
anshu
singh
ankit
ashuto
ashu 

I get... 我知道了

ankur
anshu
si^CPress any key to continue . . .

In a terminal (aka command line), Ctrl+C kills the program immediately. 在终端(又名命令行)中, Ctrl+C立即终止程序。 It doesn't wait for anything or anyone. 它不等待任何东西或任何人。 Thus, your program is literally stopping in the middle of execution, so what it does and doesn't do is a total crapshoot. 因此,您的程序实际上在执行过程中停止,因此它执行和不执行的操作都是完全失败。

In some cases, you may actually want Ctrl+D (Linux/Unix) or Ctrl+Z (Windows), which signifies "end of document". 在某些情况下,您实际上可能需要Ctrl+D (Linux / Unix)或Ctrl+Z (Windows),它们表示“文档结束”。 That may be interpreted as "end of input" without otherwise interrupting the program. 可以将其解释为“输入结束”,而无需中断程序。 However, your results may vary. 但是,您的结果可能会有所不同。

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

相关问题 如何解决 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++? 覆盖Ctrl-C - Override Ctrl-C 只有当我在终端上使用 CTRL + C 时,循环才会终止 - While loop will only terminate if I use CTRL + C on the terminal 使用 QProcess 将 EndOfText (Ctrl-C) 发送到交互式 shell - Use QProcess to send EndOfText (Ctrl-C) to interactive shell 我可以输入输入,但是当我在 Visual Studio 2017 中的 C++ 中运行我的代码 (CTRL+F5) 时,我看不到 output - I can enter the inputs but I'm not able to see the output when I run my code (CTRL+F5) in C++ in visual studio 2017 在QMessageBox中,如何添加到Ctrl-C复制的文本中? - In QMessageBox, how do I add to the text copied by Ctrl-C? 如何捕捉 ctrl-c 事件? - How can I catch a ctrl-c event? 如何在Linux中使用ctrl-c制作wxTextCtrl句柄 - How do I make wxTextCtrl handle with ctrl-c in linux Visual Studio 2013 C ++控制台程序中的输入结束 - End of Input in a Visual Studio 2013 C++ Console Program 创建新项目时,如何更改Visual Studio 2013(C ++)中的默认#include? - How to change default #includes in Visual Studio 2013(C++) when I create a new project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM