How to call functions from the command line

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AmmarN
    New Member
    • Mar 2007
    • 18

    #16
    Originally posted by horace1
    I assume your variable command is a C++ string - also check that all your comparisons are == and not =.
    This little program which look similar to your idea works OK
    Code:
    // very simple command line menu
    
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
           string command("");;
           while(command != "Q" && command !="q")    // exit on Q or q
              {
               printf("Select from command\n"
                       "  Open, Process, Save, Q\n   enter command ?");
               cin >> command;
               if(command=="Open")    cout << "Open" << endl;  else
               if(command=="Process") cout << "Process" << endl;  else
               if(command=="Save")    cout << "Save" << endl;  else
                                      cout << "Illegal command try again" << endl;
               }
    }
    THANK YOU VERY MUCH FOR YOUR TIME AND VALUABLE HELP.I got this working. I do have another little question though.

    I would like to convert a short in to 2 chars. Since short is 2 bytes i would like to isolate them and convert them into 2 chars.

    Any suggestions would be appreciated.
    Thanks in advance.

    Comment

    Working...