an eliza program code i found on the net.

hello.

i was curious and found a code for a basic eliza chatbot in c++ three files total.
with use of boost library however when i run it i get many warnings and an error messages... in msvc++ it works good but not when i copy it to codeblock using mingw 64 bit compiler i get these error / warning messages :

the warning and errors list is massive to long to post here

i'm using codeblocks with minGW 64 bit compiler and boost c++ lib.

the code also is very long so let me just give you the url to the source code:

[URL] http://www.martinbroadhurst.com/eliza-in-c.html [/URL]

basically a lot of warnings and a few errors:

here are the errors i find when trying to compile:

D:\repo\cpp_codeblocks_projects\cpp_eliza_chatbot_test1\eliza_chatbot_text1\eliza.hpp|74|error: extra ';' [-Wpedantic]|

C:\Program Files\CodeBlocks\MinGW\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++\bits\stl_iterator_base_types.h|162| recursively required by substitution of 'template<class _Iterator> struct std::__iterator_traits<_Iterator, std::__void_t<typename _Iterator::iterator_category, typename _Iterator::value_type, typename _Iterator::difference_type, typename _Iterator::pointer, typename _Iterator::reference> > [with _Iterator = boost::algorithm::split_iterator<__gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> > >]'|

D:\boost_codeblocks\boost_1_74_0\boost\regex\v4\regex_traits.hpp|169| [ skipping 2 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]|

D:\boost_codeblocks\boost_1_74_0\boost\regex\v4\regex_traits.hpp|169| [ skipping 2 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]|

D:\boost_codeblocks\boost_1_74_0\boost\regex\v4\regex_traits.hpp|75| [ skipping 3 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]|

D:\boost_codeblocks\boost_1_74_0\boost\regex\v4\cpp_regex_traits.hpp|926| [ skipping 4 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]|

D:\boost_codeblocks\boost_1_74_0\boost\regex\v4\regex_traits.hpp|169| [ skipping 2 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]|

D:\boost_codeblocks\boost_1_74_0\boost\regex\v4\regex_traits.hpp|169| [ skipping 2 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]|

D:\boost_codeblocks\boost_1_74_0\boost\regex\v4\regex_traits.hpp|75| [ skipping 3 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]|

D:\boost_codeblocks\boost_1_74_0\boost\regex\v4\cpp_regex_traits.hpp|926| [ skipping 4 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]|
Last edited on
See:

$(CXX) $(CXXFLAGS) -g -std=c++11 eliza.cpp main.cpp -o eliza -lboost_regex

It requires c++11. Maybe your compiler is outdated.
hello...

my mingw compiler support c++11 c++14 and c++17 GNU and ISO (g++)
hello i succeeded finally to resolve the issue - simply by adding lboost_regex libraries to "linker libraries" i added 2 libraries "libboost-regex-mt-d-32" and "libboost-regex-mt-d-64" (if i remember correctly) and it compiles and run without warnings or errors :)
hello i'm trying to modify the eliza chatbot code so the input/output will be written into a log text file... but it gives errors and won't compile...

here is the modified code:

file "main.cpp"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <fstream>
#include <string>
#include "eliza.hpp"

static void add_responses(MB::eliza& el);

int main()
{
    std::ofstream myfile("eliza_log.txt");
    if(myfile.is_open()) {
    MB::eliza el;

    add_responses(el);

    std::cout << "Hello. I'm " << el.name() << ". How are you feeling today?\n";
    std::string input;
    while (std::getline(std::cin, input) && input != "quit") {
        myfile<<input<< std::endl;
        std::cout << el.respond(input) << "\n";
        myfile<< el.respond(input)<< std::endl;


    } myfile.close();
    }
}


also tried this using variable to catch the replay but still getting lot's of errors
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <fstream>
#include <string>
#include "eliza.hpp"

static void add_responses(MB::eliza& el);

int main()
{
    std::ofstream myfile("eliza_log.txt");

    MB::eliza el;
//    std:string output;
    add_responses(el);

    std::cout << "Hello. I'm " << el.name() << ". How are you feeling today?\n";
    std::string input, out;
    while (std::getline(std::cin, input) && input != "quit") {
        if(myfile.is_open()){
        myfile<<input<< std::endl;
        out = el.respond(input);
        std::cout << out << "\n";
        myfile<< out << std::endl;
        }


    }myfile.close();
}
Last edited on
succeeded

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>
#include <fstream>
#include "eliza.hpp"

static void add_responses(MB::eliza& el);

int main()
{
    MB::eliza el;

    add_responses(el);

    std::cout << "Hello. I'm " << el.name() << ". How are you feeling today?\n";
    std::string input;
    std::ofstream ofs ("eliza_log.txt", std::ofstream::out);
    while (std::getline(std::cin, input) && input != "quit") {
        ofs << input << "\n";
        std::string out2 = el.respond(input);
        std::cout << out2 << "\n";

        ofs << out2 << "\n";
    }ofs.close();
}
Topic archived. No new replies allowed.