首页
学习
活动
专区
圈层
工具
发布

捕获STDIN
EN

Stack Overflow用户
提问于 2010-11-29 22:50:59
回答 1查看 265关注 0票数 3

在创建subversion存储库时,会将许多挂钩模板文件放入文件系统中。在检查示例precommit钩子时,它详细说明了钩子是通过参数传递的信息执行的,看起来也是通过STDIN传递的。

代码语言:javascript
复制
# ... Subversion runs this hook by invoking a program
# (script, executable, binary, etc.) named 'pre-commit' (for which
# this file is a template), with the following ordered arguments:
#
#   [1] REPOS-PATH   (the path to this repository)
#   [2] TXN-NAME     (the name of the txn about to be committed)
#
#   [STDIN] LOCK-TOKENS ** the lock tokens are passed via STDIN.

捕获参数是微不足道的,但是程序如何捕获STDIN?下面的代码片段在int main(...)中运行没能收集到任何东西。

代码语言:javascript
复制
char buffer[1024];
std::cin >> buffer;
buffer[1023] = '\0';

我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-11-29 22:55:59

逐行阅读输入的最简单方法是以下范例:

代码语言:javascript
复制
std::string line;
while(getline(line, std::cin)) {
    // Do something with `line`.
}

它也是安全、可靠和相对有效的。不要在不必要的情况下摆弄字符缓冲区。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4304843

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档