タグ

ブックマーク / faithandbrave.hateblo.jp (2)

  • getlineはsplitに使える - Faith and Brave - C++で遊ぼう

    <string>ヘッダにあるstd::getline()関数は、行単位の読み取りだけでなく、区切り文字を指定するバージョンもあるので、splitの実装に使えたりする。 #include <iostream> #include <string> #include <sstream> #include <vector> std::vector<std::string> split(const std::string& input, char delimiter) { std::istringstream stream(input); std::string field; std::vector<std::string> result; while (std::getline(stream, field, delimiter)) { result.push_back(field); } retu

    getlineはsplitに使える - Faith and Brave - C++で遊ぼう
  • C++のコンパイルエラー爆発を競うコンテスト - Faith and Brave - C++で遊ぼう

    Results of the Grand C++ Error Explosion Competition 少し前に、C++のコンパイルエラーの長さを競うコンテストが開催されていました。 受賞のカテゴリは2つあり、ひとつめは最小コードで最大のコンパイルエラーを出した人、もうひとつは芸術的な評価による受賞です。 最小コードで最大のコンパイルエラー この部門で優勝したのはEd Hanwayさんという方で、ソースコード量に対して59億倍のコンパイルエラーメッセージを出力したそうです。 それには、自身を2回インクルードするという手法が使われていたそうです。 #include ".//.//.//.//jeh.cpp" #include "jeh.cpp" 次点として、インクルードに後方参照を使用した、7億9千万倍のコンパイルエラーを出力するコード: #include "set>.cpp" #incl

    C++のコンパイルエラー爆発を競うコンテスト - Faith and Brave - C++で遊ぼう
  • 1