Friday 31 August 2012

First C/C++ Executable or Binary File

If your C/C++ configuration is okay you can be able to create an executable file with any kind of a normal text editor e.g., notepad if you're using windows. An executable file is also a binary file in other words.For your information you do not need any specialized editor to do this.

Let's do an example;
  1. Open your text editor i.e., notepad and type the following code;
             #include <iostream>
             #include <string>
             using namespace std;

             int main(){
             string n ("User");
             cout << "Enter your name: ";
             getline(cin, n);
             cout << "\nWelcome to C++ programming, " << n << "!\n" << endl;

             return 0;}

     2.  Save this file as Hello.cpp or Hello.cc on your desktop (Note: It should not have any other extension).
     3.  Go to your shell or command prompt and change directory to desktop, e.g.,
           cd  C:\Users\RAWG\Desktop
    4.   Type the following;
           c++ Hello.cpp                   {to compile c++}
    5.    An executable will be created on your desktop "a.exe".
    6.    On your command prompt or shell type the file's name "a" i.e., a.exe.
    7.    It should ask for your name then display "Welcome to C++ programming, <name>!".
    8.    Do the same process for a C executable save it as "Hello.c".
           Here is the code for a C executable;
            #include <stdio.h>

            int main(void )
           {
            printf("Welcome to C programming!\n" );
            return 0;}
   9. On any other platform go to your shell and use your OS editor follow the instructions as above.

  



No comments:

Post a Comment