diff --git a/SS2301-02/ss2301_02.cpp b/SS2301-02/ss2301_02.cpp index 6828690..87196ca 100644 --- a/SS2301-02/ss2301_02.cpp +++ b/SS2301-02/ss2301_02.cpp @@ -2,6 +2,7 @@ #include #include #include +#include const std::set LOWERCASE_WORDS = { "a", "an", "and", "the", "in", "on", "at", "by", "for", @@ -31,7 +32,7 @@ for (size_t i = 1; i < word.size(); ++i) { word[i] = std::tolower(word[i]); } - } else { // 追加 + } else { word = toLower(word); } result += word; @@ -41,10 +42,25 @@ return result; } -int main() { - std::string input = "C++ LANGUAGE IS A PROGRAMMING LANGUAGE."; +int main(int argc, char* argv[]) { + std::string input; + + // 引数が与えられた場合、それをファイル名として読み込む + if (argc == 2) { + std::ifstream file(argv[1]); + if (!file) { + std::cerr << "Error: Could not open file: " << argv[1] << std::endl; + return 1; + } + std::getline(file, input, '\0'); // ファイルの内容を全て読み込む + file.close(); + } else { + std::cout << "Enter the text to capitalize (end with Enter): "; + std::getline(std::cin, input); + } + std::string output = capitalize(input); - std::cout << output << std::endl; // C++ Language Is a Programming Language. + std::cout << output << std::endl; return 0; }