[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

To compile and execute a C++ file in UNIX

I compiled a c++ file in Unix as gcc filename.cc. It didn't give me any error. But when I type a.out next it is saying file not found or bad command. The same thing is happening when I try to compile and run a C file giving the command cc filename.c and a.out.

Kindly help me.
0
thenmozhia
Asked:
thenmozhia
  • 2
  • 2
1 Solution
 
jhanceCommented:
Try this:

/a.out

My guess is that you're logged in as root and the default PATH for root is NOT to include the current directory or ".".  By saying ./<program_name> you're telling the shell to run the a.out in the current working directory.

You can also compile with the -o option like this:

gcc filename.c -o filename

so the output will go to filename instead of to a.out.

0
 
thenmozhiaAuthor Commented:
I found Jhance answer is correct. By mistake previously I rejected his anwer. Sorry for that.

Thankyou
0
 
jhanceCommented:
OK, how about we try it again.....
0
 
thenmozhiaAuthor Commented:
o.k. and Thankyou so much.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now