CPP01 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
main.cpp
[詳解]
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* main.cpp :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/04/18 15:28:42 by kamitsui #+# #+# */
9/* Updated: 2025/04/23 00:42:39 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
26#include "FileReplacer.hpp"
27#include <iostream>
28#include <string>
29
45int main(int argc, char **argv) {
46 if (argc != 4) {
47 std::cerr << "Usage: " << argv[0] << " <filename> <string_to_find> <string_to_replace>" << std::endl;
48 return 1;
49 }
50
51 std::string filename = argv[1];
52 std::string s1 = argv[2];
53 std::string s2 = argv[3];
54
55 if (s1.empty()) {
56 std::cerr << "Error: The string to find (s1) cannot be empty." << std::endl;
57 return 1;
58 }
59
60 try {
61 FileReplacer replacer(filename, s1, s2);
62 replacer.processFile();
63 std::cout << "Successfully processed file: " << filename << " -> " << filename << ".replace" << std::endl;
64 } catch (const std::exception &e) {
65 std::cerr << "Error: " << e.what() << std::endl;
66 return 1;
67 }
68
69 return 0;
70}
Declares the FileReplacer class for replacing strings in a file.
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
ostream cerr
ostream cout
bool empty() const noexcept
virtual const char * what() const noexcept
A class that handles replacing occurrences of a string within a file.
void processFile()
Processes the input file and performs the string replacement.
int main()
Main function of the program.
Definition main.cpp:44