How to make C++ program a Terminal program (UNIX)
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";
}
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.