list initializer

This commit is contained in:
hugogogo
2022-02-07 14:47:39 +01:00
parent bb43bb40e8
commit 649b6168ef
5 changed files with 82 additions and 18 deletions

View File

@@ -16,10 +16,11 @@ LIBS =
INCLUDES = -I$(D_HEADERS)
D_SRCS = .
SRCS = main.cpp
SRCS = main.cpp \
Sed.cpp
D_HEADERS = .
HEADERS =
HEADERS = Sed.hpp
D_OBJS = builds
OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o)

32
d01/ex04/Sed.cpp Normal file
View File

@@ -0,0 +1,32 @@
#include "Sed.hpp"
Sed::Sed(char *file, char *find, char *replacement)
: _file( file )
// , _new_file( file.append(".replace") )
, _find( find )
, _replacement( replacement )
{
// this->_buf =
return;
}
Sed::~Sed() {
// delete[] this->_buf;
return;
}
void Sed::replace() {
std::ifstream file(this->_file.c_str());
char c;
while (file.get(c))
{
std::cout << c;
}
}

27
d01/ex04/Sed.hpp Normal file
View File

@@ -0,0 +1,27 @@
#ifndef SED_HPP
# define SED_HPP
#include <iostream>
#include <string>
#include <fstream>
class Sed {
public:
Sed(char *file, char *find, char *replacement);
~Sed();
void replace( void );
private:
// std::string _buf;
std::string const _file;
std::string const _new_file;
std::string const _find;
std::string const _replacement;
};
#endif

View File

@@ -1,24 +1,28 @@
#include "Sed.hpp"
#include <iostream>
#include <string>
#include <fstream>
int main() {
int sed_error(std::string msg) {
std::ifstream file("test.txt");
std::cout << msg << std::endl;
return 1;
}
// read words separated by whitespaces or newlines
// std::string str;
// while (file >> str)
// std::cout << str << std::endl;
void cpp_sed(char **av) {
// skip whitespaces or newlines
// char c;
// while (file >> c)
// std::cout << c << std::endl;
// seems good
char c;
while (file.get(c))
std::cout << c;
Sed sed(av[1], av[2], av[3]);
sed.replace();
}
int main(int ac, char **av) {
if (ac != 4)
return sed_error("you must provide 3 parameters : <file> <string 1> <string 2>");
cpp_sed(av);
return 0;
}

Binary file not shown.