C/C++ Tutorial # 1 Hello World

show more
Upvotes (2)
Comments (1)
Sorted by:
  • [ – ] Fighting_Zenith reply Nice, but would your examples work with Notepad++ or Programmer's Notepad?
    • [ – ] Jaylight parent reply If you want to use Notepad++ or Programmer's Notepad or even just plain notepad (but that would suck for writing code) or editors such as vi, vim, nano, gedit, etc, to write this program, you can do that, and save the file as main.c or main.cpp (or anything dot c or anything do cpp) (dot c is for c programs and dot cpp is for c++ programs). Note, I don't think you can use Wordpad, and I'm pretty sure you can't use MS Word, Wordperfect, Open Office or Libre Office or anything fancy like those, because they will add hidden characters to your code that the compiler won't understand. Not that you would want to use those editors anyway. Then to compile and run the program, if you don't have a tool to do that. I use Linux, and am less familiar with Windows & Mac Environments, but I found this resource for Windows http://www.mingw.org/wiki/mingw_for_first_time_users_howto and for Mac, I found this resource: https://www.mkyong.com/mac/how-to-install-gcc-compiler-on-mac-os-x/ For Linux,...more open up the terminal window with (Ctrl+Alt+T). Then you need to make sure you have the gcc and g++ compiler installed if it isn't already, by typing into the terminal: sudo apt-get install update sudo apt-get install gcc sudo apt-get install g++ gcc is the C compiler for Linux g++ is the C++ compiler for Linux It doesn't matter which one you use for this example, but, sometimes you need the C compiler vs the C++ compiler or the C++ compiler vs the C compiler. Then do: cd <path-where-your-program-is-located> gcc <name-of-program-file> OR g++ <name-of-program-file> This will produce a a.out file which is the compile version of your code with the 1's & 0's the computer understands. To run a.out type ./a.out If you don't want the compiled file be called a.out, you can use gcc <name-of-program-file> -o <name-of-compiled-file> OR g++ <name-of-program-file> -o <name-of-compiled-file> If you get a permission error, you can try: sudo ./a.out If you still get permission errors, you can try: sudo chmod u+x a.out chmod stands for "change mode" This will make a.out executable for its user And, if you still get permission errors: you can try: sudo chown <your-user-name> a.out Chown stands for "change owner" This, will make a.out owned by you. If you don't know your username, you can type: whoami And the output is your username to use in the `sudo chown` command.
Download the Vidme app!