2016-06-20から1日間の記事一覧

C++ の stream 入力で末尾にゴミが入ってるかどうかを確認する

C++

Twitter でツッコまれたんですが、例えば以下のように std::stringstream を使った場合はエラーになりません。 #include <iostream> #include <sstream> int main() { // 末尾にゴミがある std::stringstream str("123x"); int x; str >> x; std::cout << x << std::endl; // =></sstream></iostream>…