简体   繁体   中英

how to compile C++ code through terminal

I am using the atom text editor. I want to compile a simple "hello world" program using the osx terminal (yosemite version 10.10.4). I named the program ctut.cpp. So, then on the terminal I wrote the command g++ ctut.cpp but ended up getting

clang: error: no such file or directory: 'ctut.cpp'

clang: error: no input files

why is it saying the file does not exist?

You need to pass the file's path if it is not in your home directory. If your file is inside a directory named Code inside the Home directory, then you need to do g++ ~/Code/ctut.cpp .

You do need to cd into the directory where you saved ctut.cpp or use the files path as explained in chintan's answer although your also not typing the full command. It should be g++ ctut.cpp -o ctut then to run the program you type ./ctut

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM