2013-02-18から1日間の記事一覧

タブ区切りのテキストを読み込む

これが一番楽っぽい。 #include <iostream> #include <fstream> #include <string> #include <vector> int main() { const std::string file_name = "test.txt"; std::ifstream file(file_name.c_str()); std::string temp; std::vector<std::string> items; while (getline(file, temp, '\t')) { items.push_</std::string></vector></string></fstream></iostream>…

文字列を全て大文字(小文字)に変換したい

C++

時折ド忘れするのでメモ。 要するにtransform + toupper(tolower)の組み合わせが一番楽に出来るぞと。 #include <iostream> #include <string> #include <algorithm> int main() { std::string x("abCdef"); std::transform(x.begin(), x.end(), x.begin(), ::toupper); std::cout << x; r</algorithm></string></iostream>…