I am making a command line program, and I was wondering how to get different parts of sentences, so lets say if someone entered cd Windows/Cursors
, it would detect (with an if statement) that they entered cd
and then (in that same if statement) it would select the rest of the sentence, and set that as the directory. This is my code:
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
int main()
{
while (1)
{
string directory = "C:/";
string promptInput;
string afterPrint;
string prompt = "| " + directory + " |> ";
cout << prompt;
cin >> promptInput;
if (promptInput == "")
{
}
else if (promptInput == "h:/")
{
directory = "H:/";
}
if (promptInput != "") {
cout << " " << afterPrint << "\n";
}
}
return 0;
}
I haven't tried anything yet, so I am open to suggestions.
Help will be highly appreciated.
-Caleb Sim