[英]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.