0

I wrote this simple C++ program to compare two strings for a match. Although basic, it's very useful to me as I often need to verify details multiple times a day.

I want to initiate the program with a command name e.g. check4match (the program name) so I can run the program in the terminal.

#include <iostream>
#include <string>
using namespace std;

void match(string, string);
int main() {
    
    string addrOne, addrTwo;
    
    cout<<"Insert str one: "; cin>>addrOne;
    cout<<"Insert str two: "; cin>>addrTwo;
    match(addrOne, addrTwo);
    
    return 0;
}

void match(string addrOne, string addrTwo){
    if(addrOne == addrTwo)
        cout<<"SAFE: strings match";
    else
        cout<<"WARNING: N0 match found";
}
6
  • 3
    In a terminal, go to the directory (with cd) where the match executable file is located. Then run ./match. Or (still in the terminal) use the full path to the program (/some/path/to/match). Commented Jan 20, 2022 at 11:23
  • 2
    You have many options: Use PATH environment var and set it in addition to the path where your executable is placed. Create in your shell an alias which points to the file, copy your executable to a common path which is typically already in PATH like /usr/local/bin Commented Jan 20, 2022 at 11:25
  • 1
    Windows or UNIX? Commented Jan 20, 2022 at 11:29
  • Using UNIX (mac) Commented Jan 20, 2022 at 11:31
  • 1

1 Answer 1

1

Ok, as always relatively simple in the end. So chmod a+x didn't work to make the cpp program executable. Simple make filename (without the .cpp extension).

Then I moved the newly made .exe file to /usr/local/bin. I had to drag & drop the file, as moving via terminal command wasn't allowed, even with sudo.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.