Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (0)

Powered by Vanilla. Made with Bootstrap.
Beginning C++ Hello World
  • Xin
    Posts: 3,251
    [---------------------------------------------------]
    Beginning C++ Hello World
    Written By Xinapse
    For iExploit.org

    [b]Difficulty:Easy

    [---------------------------------------------------][/b]

    -------[Structure of a Program
    All C++ programs have to follow this basic structure
    // MyProg
    int main()
    {
    ...
    }

    If you end up missing any of this your program will end up in a syntax error and will not compile. The extensions of a C++ file usually end in .cpp, this is essential to remember when looking for your scripts. These are the codes before they are compiled, the point of compiling the code is to convert into a machine language program that carries out a certain task so it can be run. In windows they are converted into executables .exe.

    To write a program you need an editor, used to write your .cpp file, and a compiler as we discussed in part 1. Nowadays these tools usually come together in a package.

    -------------[Creating a Project Windows

    For this example, we will be using codeblocks, firstly load up CodeBlocks ide,
    choose File>New>Project, select console application and press go. Select C++ as the language and name the project you want to make, finally click finish. In the management window on the left double click main.cpp under sources, now you can enter your code. As you can see a template is already there ready for you to enter the code.

    Firstly you need to type, if it isnt already there
    #include <iostream>

    This imports all of the iostream code and commands so it is recognised and works in the program.
    Next we need to type
    int main() 

    This is just declaring the program has started , and essential in all programs.
    Now we move onto the actual code. As we said before you put the code inside { ... } So lets make a simple command line program saying Hello iExploit, this is a hello world program.
    So firstly lets type
    using namespace std; 

    telling it the library to find the object.
    Now lets get the cli to display Hello iExploit
    cout << \"Hello iExploit\";

    This is a basic writeline code and will display on the command line.
    We now want a new line so lets type
    cout << endl;

    Finally lets say this is a hello world program by typing
    cout << \"This is a Hello world program\" << endl;
    return 0;
    }

    This code states its the end of the program so computer can stop reading code, now we need to compile this so lets, go build and run or F9, and see what happens,
    the Output should be
    Hello iExploit
    This is a Hello world program

    Congratulations this is your first program made in windows! Keep it up.

    --------[Creating a Program in Linux
    I will now show you the steps to creating a program in linux, i will not type out the code again but instead just tell you how to create and compile the program.
    Firstly create a file myprog.c and enter the following code

    #include <iostream>

    int main()

    {
    using namespace std;
    cout << \"Hello iExploit\";
    cout << endl;
    cout << \"This is a hello world program\" << endl;

    return 0;
    }

    Then save it and type
    g++ -o myprog myprog.c

    You can now run your program by typing
    ./myprog

    Stay tuned for the next section on variables!
    Xin
  • chroniccommand
    Posts: 1,389
    Nice. I prefer to use

    std::cout >> \"Hello world >> std::endl;

    Instead though :P
  • Xin
    Posts: 3,251
    if you include namespace std you dont need to put std do you?
    Xin
  • chroniccommand
    Posts: 1,389
    said:


    if you include namespace std you dont need to put std do you?



    I don't think so, but I usually code in C, not C++
  • Xin
    Posts: 3,251
    Well the program works fine for me anyway :)
    Xin
  • DizzY
    Posts: 155
    lol you need to proof read

    "Beginning C++ Hell World"
  • Xin
    Posts: 3,251
    said:


    lol you need to proof read

    "Beginning C++ Hell World"



    haha thanks for the heads up :)
    Xin
  • Bursihido
    Posts: 406
    good tutorial :) thanks



    tooshrt
  • Xin
    Posts: 3,251
    Glad you liked it burihido :)
    Xin
  • Bursihido
    Posts: 406
    pls make more tutorials on c++ ?..........
  • Xin
    Posts: 3,251
    More coming up soon
    Xin