2010-11-29 12 views
3

Subversionリポジトリを作成するときに、いくつかのフックテンプレートファイルがファイルシステムにドロップされます。サンプルのプリコミットフックを調べると、フックは引数で渡された情報で実行され、一見STDINによって実行されることも詳しく説明されています。STDINのキャプチャ

# ... 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(...)で実行される次のコードスニペットは何も収集できません。

char buffer[1024]; 
std::cin >> buffer; 
buffer[1023] = '\0'; 

私は間違っていますか?それはまた、安全で信頼性が高く、比較的効率的です

std::string line; 
while(getline(line, std::cin)) { 
    // Do something with `line`. 
} 

答えて

5

ライン入力によるラインを読むための最も簡単な方法は、次のパラダイムです。 charバッファで不必要に悩んではいけません。

+0

合意して、私は通常バッファー・アレイから離れていますが、それは簡単なPoCコードでした。 – Konrad