I need help with a program i am writing. It takes in a line from the user and then decides wat to do. there are to many options to spesify. some of the options are:

    set TARGET 453.212.556.22 

This command will differ becuase the host will never be the same.

    set FUNCTION create:tcp

This function will also differ becuase there are allot of things that can be created like: reverse tcp connection, vnc session, webcam session.

    use NETWORK

That will be the defualt gateway, there is also going to be allot of them.

    >: download "filename" "destination"

This is going to download a file from the computer to the other computer.

See my problem isnt to write these functions. The problem is i cant seem to make my "input string" into keywords so that it can choose the write action. I cant really go and type:
All the way up to newest ip address, that would take ages and the program would be to big.

So i need to make my program read the firs few words:
and then get the next word:

One might say that i am trying to make a terminal (for linux users) or a cmd (for microsoft user).
it should act just like a cmd / terminal: getting the user input. deviding it into keywords so that it can choose wat to do.

You cant tell me that microsoft's or linux's terminal has each and every ipadress + any other possible name of a program or directory in its database. They must have used keywords.

Here is my code:

NOTE: this code istn my actual code, this is just to demonstrate what i am saying:

    #include <iostream>
    #include <someotherheaders>

    using namespace std;

    int vncsession();
    //connects to other computer using vnc

    int downloadfile(string filnamelocation, string filenamedest)
    // downloads a file from target to destination

    int main()
        string input;

        cout<<">: ";

        getline(cin, input);

        if(line == "use FUNCTION ")
        else if (line == "download ")
            downloadfile(keyword1, keyword2);

So my question actually is: How am i going to make my program brake that line into keywords and then do what it must. I have tried using an enum before but it didnt work.

4 Years
Discussion Span
Last Post by MasterHacker110

Well if you want to parse a string the best way i can think of is to you a stringstream. You get the input from the user using getline like you have and then you would put the string into the stringstream. After that you would output all of the differnt parts into som sort of contianer. After that you just go through the continaer and handle accordinginly. Here is a little sample of how to do that.

// to break a up string
#include <vector> // for vector
#include <sstream> // for stringstream
#include <iostream>
#include <string>

int main()
    std::stringstring ss;
    std::string input, temp;
    std::vector<string> comand;
    std::cout << ">: ";
    std::getline(cin, input);
    ss << input;
    // brak up line and put each part into the vector
    while( ss >> temp)
    // display vector
    for(size_t i = 0; i < comand.size(); i++)
        std::cout << comand[i] << std::endl;
    std::cin.get(); // pause program
    return 0;

See man, that is exactly what i needed, thanks so much for it. i have been looking all over the web for this and couldnt find anything. ill do it like that.

This question has already been answered. Start a new discussion instead.
Be sure to adhere to our posting rules.