- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是C++的初学者,在看《C++ Primer》第5本书时,我对第1.4.4章有点困惑。当我在 1.4.4 中运行程序时,这是我电脑中的步骤:
#include <iostream>
int main()
{
// currVal is the number we're counting; we'll read new values into val
int currVal = 0, val = 0;
// read first number and ensure that we have data to process
if (std::cin >> currVal)
{
int cnt = 1; // store the count for the current value we're processing
while (std::cin >> val)
{ // read the remaining numbers
if (val == currVal) // if the values are the same
++cnt; // add 1 to cnt
else
{ // otherwise, print the count for the previous value
std::cout << currVal << " occurs " << cnt << " times" << std::endl;
currVal = val; // remember the new value
cnt = 1; // reset the counter
}
} // while loop ends here
// remember to print the count for the last value in the file
std::cout << currVal << " occurs " << cnt << " times" << std::endl;
} // outermost if statement ends here
return 0;
}
Ctrl+D
42 occurs 5 times
55 occurs 2 times
62 occurs 1 times
Ctrl+D
100 occurs 3 times
我的问题是为什么我要输入第二次Ctrl+D,我的代码环境是Ubuntu+GCC,我也是在VS2013中运行的,只需要输入一次Ctrl+D。
我在 stackoverflow 中搜索过,但没有得到我的答案。
Incorrect output. C++ primer 1.4.4
confused by control flow execution in C++ Primer example
C++ Primer fifth edtion book (if statement) is this not correct?
最佳答案
在 Linux 中,Ctrl+D
并非无条件地表示“文件结束”(EOF)。它的实际意思是“将当前待处理的输入推送给等待阅读它的任何人”。如果输入缓冲区非空,则按 Ctrl+D
不会在缓冲区末尾创建 EOF 条件。只有在输入缓冲区为空 时按Ctrl+D
,才会产生EOF 条件。 (有关更多技术说明,请参见此处:https://stackoverflow.com/a/1516177/187690)
在您的情况下,您将数据作为单行输入,然后在最后按 Ctrl+D
。这会将您的输入推送到您的程序,并使您的程序读取和处理数据。但它不会在您的输入结束时产生 EOF 条件。
因此,一旦循环读取了所有输入数据,您的程序就不会将其视为 EOF。该循环一直在等待空的输入缓冲区以获取更多数据。如果此时您再次按下 Ctrl+D
,它将被识别为 EOF,您的程序将退出循环并打印最后一行。
这就是为什么您必须按 Ctrl+D
两次:第一次按与 Enter
键的效果非常相似。并且只有第二次命中会产生 EOF 条件。
关于C++ 入门第 5 期 1.4.4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28289534/
我似乎对 git 存储库有权限问题。 当我 pull 入一个不是我的 Linux 用户创建的目录时,我出现了这个错误。 fatal: Unable to create '/home/---/.git/
在 Git 中,您可以将给定目录克隆到给定目录: git clone ssh://gitolite@dev.bipper.com:3687/com/bipper/kids/portal 当我运行我们
目前,如果您在分支 V2 中并执行“git pull origin V3”,它会将 V3 merge 到 V2,甚至不会发出警告或提示。这个选项可以以某种方式被阻止吗?我在这里阅读了所有类似的问题,人
我刚开始使用 Oracle 的 Coherence 缓存,我注意到这一点:如果我在缓存中放入一个 ConcurrentHashMap 对象,当我检索它时,我可以看到它被转换为一个普通的 HashMap
看起来我缺少对 git pull 和 git commit 的基本理解,假设我在分支上工作,而它在我更新时被其他开发人员更新了在本地做我的工作。我应该在发出 git pull 之前提交更改,还是应该执
好的。所以我以为我已经舔过了……但现在…… 我有一个项目,其中包含一个来自 GitHub 的小型库作为子模块。在该 super 项目的原始版本中,子模块按预期工作。 但是,我只是克隆了 super 项
使用 Visual Studio Code 中的内置 Git,我看不到将指定的远程分支 pull 入当前分支的方法。我可以这样做吗? 示例:我正在分支 myBranch 上工作,更改已 merge 到
当我尝试提交或 pull 此错误时 Bus error (core dumped) 发生了! 当我用 gdb 调试它时,(gdb git,run commit -a,where) 结果是: mucul
我对默认 Rails Rake 任务的预期用途有点困惑,想咨询一下我是否应该使用 db:reset或编写自定义 Rake 任务。没什么聪明的,只是日常管理,而且我很可能会错过一个明显的文档,因为我是
所以我做了: git reset --hard #commithash # make a bunch of changes, fixes and so on. git add -A git commi
我已使用以下命令成功部署到 firebase 托管应用: firebase init firebase deploy 在这个阶段,我正在执行 git pull 以将 repo 下 pull 到暂存服务
当尝试在 Eclipse 的 git 存储库中 pull (团队|从上下文菜单中 pull )时,出现 Could not get advertised Ref for branch refs/hea
我是一名优秀的程序员,十分优秀!