Documentation & Help
- Documentation
If you want to viewing the documentation of a particular command you can use man (manual) command
Example:
$ man ls
It will display the documentation for the ls command.
- Help
Many commands that you issue at the command prompt are executable programs stored in the filesystem. They are usually in /bin
, /usr/bin
, or /usr/local/bin
.
However, some commands are built-in shell commands, such as cd. To find out information about built-in shell commands, use help
Hello World!
In your working directory, creat a sub-directory named “Hello”. Open that folder with vscode and create a file called helloworld.cpp with the following contents:
#include <iostream>
int main() {
std::cout << "Hello World" <<std::endl;
return 0;
}
Save the file and execute the following commands:
c++ hello.cpp
./a.out
std::vector
std::vector is a generic container. It can hold data of any type – but we have to specify the type to the compiler.
To create a vector of integers with ten elements, we would use the statement
std::vector x(10);
In the angle brackets, the type that the vector is holding is specified. The size of the vector we are creating has 10 elements.
int a=x[3];
Assigns the value of the element at index 3 to the variable a.
Attention: C and its derivative languages use “zero-based” indexing, meaning the first element is at index location 0. So, x[3]
is actually the fourth element!!!
This is because an index in C++ is not the ordinality of the element, but rather the distance the element is from the beginning of the vector. Thus the first element is distance zero from the beginning and so is indexed as x[0]
.
We can loop through a vector from beginning to end using the square bracket notation:
for (int i = 0; i<5; ++i) {
x[i] = 3*i;
}
++i
means the value of i
should be incremented by one at the end of the loop. This loop will create a x from 0 to 12.
The i
will be 0, 1, 2, 3, 4 in each iteration.