Skip to content

Commit

Permalink
Add Hello World example
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasIriarte committed Dec 3, 2023
1 parent 44d8ea0 commit c771620
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 0 deletions.
1 change: 1 addition & 0 deletions content/docs/Cpp/RAII/index.es.org
@@ -1,6 +1,7 @@
---
title: RAII
linkTitle: RAII # The title of left navigation, optional.
navWeight: 500 # Upper weight gets higher precedence, optional.
categories:
- C++ programming
series:
Expand Down
1 change: 1 addition & 0 deletions content/docs/Cpp/RAII/index.org
@@ -1,6 +1,7 @@
---
title: RAII
linkTitle: RAII # The title of left navigation, optional.
navWeight: 500 # Upper weight gets higher precedence, optional.
categories:
- C++ programming
series:
Expand Down
1 change: 1 addition & 0 deletions content/docs/Cpp/constructors/index.es.org
@@ -1,6 +1,7 @@
---
title: Constructores
linkTitle: Constructores # The title of left navigation, optional.
navWeight: 1000 # Upper weight gets higher precedence, optional.
categories:
- C++ programming
series:
Expand Down
1 change: 1 addition & 0 deletions content/docs/Cpp/constructors/index.org
@@ -1,6 +1,7 @@
---
title: Constructors
linkTitle: Constructors # The title of left navigation, optional.
navWeight: 1000 # Upper weight gets higher precedence, optional.
categories:
- C++ programming
series:
Expand Down
Binary file added content/docs/Cpp/hello-world/Compilation.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/docs/Cpp/hello-world/img.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
107 changes: 107 additions & 0 deletions content/docs/Cpp/hello-world/index.es.org
@@ -0,0 +1,107 @@
---
title: Hola Mundo!
linkTitle: Hello world! # The title of left navigation, optional.
navWeight: 10000 # Upper weight gets higher precedence, optional.
categories:
- C++ programming
series:
- C++
tags:
- C++
- Computer science
- Easy
- Basic knowledge
---

Iniciar en el mundo de la programación nunca ha sido más sencillo,
tenémos documentación prácticamente infinita, tutoriales online, y foros
altamente activos para plantear y resolver nuestras dudas.

Aun así, empezar en el mundo de C++ no es sencillo, la barrera de
entrada en relativamente alta, y es necesario un tutorial o guia
suficientemente detallada para cubrir las dudas que pueden surgir para
alguien que recién está arrancando en este maravilloso mundo.

Por tal motivo, este post busca ser una guía con simples objetivos:
1. Está orientada a lectores sin experiencia alguna en la programación.
2. Ser lo suficientemente extensiva en los pasos, pero sin entrar en
demasiados detalles técnicos.

* Las bases

** ¿Qué es C++?

C++ es un lenguaje de programación *compilado*, que se caracteriza por poseer acceso a primitivas de *bajo nivel* y abstracciones de *alto nivel*. Este lenguaje es normalmente utilizado en ambientes donde el rendimiento es un factor clave del sistema.

Un lenguaje de programación *compilado* significa que su código debe ser traducido a un ejecutable (O código máquina) antes de su ejecutado.


#+name: Compilation process
#+begin_src plantuml :file Compilation.png :exports results
User --> (Files.cpp)
User --> (Files.hpp)

(Files.cpp) --> Compiler
(Files.hpp) --> Compiler

cloud Compiler {
(Magic)
}

Compiler --> [bin.out]
#+end_src

#+RESULTS: Compilation process
[[file:Compilation.png]]


En la figura anterior, se muestra el proceso de compilación de un programa en C++. El usuario escribe el código en archivos con extensión =.cpp= y =.hpp=, los cuales son procesados por el compilador, el cual genera un ejecutable con el nombre =bin.out=.


** ¿Qué es un compilador?

Un compilador es un programa que traduce el código fuente de un programa a un ejecutable. En el caso de C++, existen varios compiladores, siendo los más populares:

- [[https://gcc.gnu.org/][GCC]]: El compilador de GNU.
- [[https://clang.llvm.org/][Clang]]: El compilador de LLVM.
- [[https://visualstudio.microsoft.com/es/vs/features/cplusplus/][MSVC]]: El compilador de Microsoft Visual Studio.


** Nuestro primer programa

Para nuestro primer programa, vamos a utilizar el compilador GCC, el cual es de código abierto y se encuentra disponible en la mayoría de los sistemas operativos. El proceso de instalación de GCC depende del sistema operativo que estemos utilizando, por lo que no se detallará en este post.


Una vez instalado GCC, vamos a crear nuestro primer programa. Para ello, vamos a crear un archivo con extensión =.cpp=, el cual contendrá el siguiente código:


#+begin_src cpp
#include <iostream>

int main() {
std::cout << "Hola mundo!" << std::endl;
return 0;
}
#+end_src

Este programa imprime en pantalla el texto =Hola mundo!=. Para compilarlo, debemos ejecutar el siguiente comando:

#+begin_src bash
g++ -o bin.out main.cpp
#+end_src

Este comando ejecuta el compilador =g++=, el cual recibe como argumento el nombre del archivo que queremos compilar (=main.cpp=) y el nombre del archivo de salida (=bin.out=).

Una vez compilado, podemos ejecutar el programa con el siguiente comando:

#+begin_src bash
./bin.out
#+end_src

Una vez ejecutado, veremos en pantalla el texto =Hola mundo!=.

** Conclusiones

En este post, hemos visto los conceptos básicos de C++, y hemos creado nuestro primer programa. Con dichos conocimientos poseemos una base para crear cualquier otro programa, compilarlo y poder ver su resultado.


99 changes: 99 additions & 0 deletions content/docs/Cpp/hello-world/index.org
@@ -0,0 +1,99 @@
---
title: Hello World!
linkTitle: Hello world! # The title of left navigation, optional.
navWeight: 10000 # Upper weight gets higher precedence, optional.
categories:
- C++ programming
series:
- C++
tags:
- C++
-Computer science
-Easy
- Basic knowledge
---

Getting started in the world of programming has never been easier, we have practically endless documentation, online tutorials, and highly active forums to ask and resolve our doubts.

Even so, starting in the world of C++ is not easy, the entry barrier is relatively high, and a sufficiently detailed tutorial or guide is necessary to cover the doubts that may arise to someone who is just starting out in this wonderful world.

For this reason, this post seeks to be a guide with simple objectives:
1. It is aimed at readers without any programming experience.
2. Be extensive enough in the steps, but without going into too many technical details.

* The bases

** What is C++?

C++ is a *compiled* programming language, characterized by having access to *low-level* primitives and *high-level* abstractions. This language is normally used in environments where performance is a key factor of the system.

A *compiled* programming language means that its code must be translated into an executable (machine code) before it is executed.


#+name: Compilation process
#+begin_src plantuml :file Compilation.png :exports results
User --> (Files.cpp)
User --> (Files.hpp)

(Files.cpp) --> Compiler
(Files.hpp) --> Compiler

cloud Compiler {
(Magic)
}

Compiler --> [bin.out]
#+end_src

#+RESULTS: Compilation process
[[file:Compilation.png]]


The figure above shows the compilation process of a C++ program. The user writes the code in files with extension =.cpp= and =.hpp=, which are processed by the compiler, which generates an executable with the name =bin.out=.


** What is a compiler?

A compiler is a program that translates the source code of a program into an executable. In the case of C++, there are several compilers, the most popular being:

- [[https://gcc.gnu.org/][GCC]]: The GNU compiler.
- [[https://clang.llvm.org/][Clang]]: The LLVM compiler.
- [[https://visualstudio.microsoft.com/es/vs/features/cplusplus/][MSVC]]: The Microsoft Visual Studio compiler.


** Our first program

For our first program, we are going to use the GCC compiler, which is open source and available on most operating systems. The GCC installation process depends on the operating system we are using, so it will not be detailed in this post.


Once GCC is installed, let's create our first program. To do this, we are going to create a file with extension =.cpp=, which will contain the following code:


#+begin_src cpp
#include <iostream>

int main() {
std::cout << "Hello world!" << std::endl;
return 0;
}
#+end_src

This program prints the text =Hello world!= on the screen. To compile it, we must execute the following command:

#+begin_src bash
g++ -o bin.out main.cpp
#+end_src

This command executes the =g++= compiler, which receives as arguments the name of the file we want to compile (=main.cpp=) and the name of the output file (=bin.out=).

Once compiled, we can run the program with the following command:

#+begin_src bash
./bin.out
#+end_src

Once executed, we will see the text =Hello world!= on the screen.

** Conclusions

In this post, we have seen the basic concepts of C++, and we have created our first program. With this knowledge we have a basis to create any other program, compile it and be able to see its result.

0 comments on commit c771620

Please sign in to comment.