C++ Semi-Inteligent AI
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: C++ Semi-Inteligent AI

  1. #1
    Join Date
    Apr 2010
    Posts
    1

    Question C++ Semi-Inteligent AI

    Hello. I'm just starting C++, but have scripted in other languages before. One of the things I aspire to do is to create an AI, but I recently ran into trouble while scripting it. What It's supposed to do follows:

    1. Prompt the user to enter a filename.
    2. Load the file.
    3. Prompt the user to enter a phrase to teach the AI (until a better method is found).
    4. Prompt the user to say something to the AI.
    5. Take what the user said, and search the data file for a line with a similar phrase in it.
    6. Print the line to the console, split at a period.

    I'm getting several errors, and am not entirely sure if everything I'm doing will work, but am hoping someone can correct me. Thanks a lot in advance.



    COPY AND PASTE INTO COMPILER:



    #include <iostream>
    #include<fstream>

    using namespace std;

    int main()
    {
    char filename[50];
    cin >> filename;

    ifstream openfile;
    openfile.open(filename,ios::app|ios:ut); // opens the file for appending and outputting

    if(!openfile.is_open()){
    cout << "Sorry, the program is experiencing errors, or the specified file does not exist. Please try again." << endl;
    }

    while(!openfile.eof()){

    char teach[50];
    cout << "First teach the AI a new phrase to help the learning process. Please use periods and proper grammar." << endl;
    cin >> teach;
    openfile << teach << " "; // it appends what you said to the file, with a space
    cout << "You taught the AI: " << teach << endl;

    char usersaid[100];
    cout << "Please type something for the AI to process, then press enter." << endl;
    cin >> usersaid;

    char delim[] = "."; // the delimiter is periods
    char line = usersaid[5]; // the first 5 characters of what they said?
    char response = getline(openfile,line,delim); // the string, "response", is the
    // line in the file that contains the first 5 letters you said,
    // but it only outputs from that spot to the next period
    cout << "AI: " << response << " " << endl; // the output


    }
    system("PAUSE");
    return 0;
    }

  2. #2
    Join Date
    Apr 2010
    Posts
    7

    Re: C++ Semi-Inteligent AI

    a) ios:ut is ios::ut.
    b) you can't write to an input file stream. use an output file stream.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center