Score:0

How to make one shortcut to execute .cpp file

tr flag

whenever I want to execute a .cpp in terminal I have to write ./ before it .

And I want to change this "./" to something else .

I found this on another thread :

cr(){
if [ "$#" -ne 1 ]; then
    echo "Usage: cr <file.cpp>"
else
    name=$(echo $1 | cut -f 1 -d '.')
    g++ $1 -o name; ./name
fi

}

It works fine but the thing is that I want to use it with flags like -DLOCAL and some others, how do I make it work?

Because right now I'm using sublime text with some templates and those (templates) require the flags to show the values in terminal .

And also if there is a way to make it work without writing the .cpp extension everytime

(ex : cr A.cpp in cr A)

Thanks !

Edit : Managed to get the flags working but still, is there a way to not write .cpp when running the shortcut?

Score:0
hr flag

The command make A will compile and link a A.cpp using default rule g++ A.cpp -o A

Ex. given

$ cat > A.cpp
#include <iostream>

int main(void) { std::cout << "Hello world" << std::endl; return 0; }

then

$ make A
g++     A.cpp   -o A

$ ./A
Hello world
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.