[Tutorial] [C++GDK] C++ basics.
#1

Recently i found out that we are able to use c++ to write scripts for samp.
But i do not see anyone making tutorials on C++ here( maybe because there are a lot available outside samp forums).
Anyhow, here is my tutorial on the basics of C++ which we can further use to write samp codes in C++.

Follow the following GitHub topic to set yourself up to be ready to script
https://github.com/Zeex/sampgdk

Author:iSteve/Srinabh Jha
Difficulty:Novic
Title:C++ basics 1.
Next Tutorial:[Tutorial] [C++GDK] Classes and Objects

Made for SA-MP forums

Starting a C++ program
the basic library needed to begin a C++ program is <iostream>.

This has to be written at the begenning of your code.

The next line you would like to add is using namespace std.

The line using namespace std; tells the compiler to use the std namespace.

Now, let us come to the main() function.
the int main() is the line where a program begins.

C++ uses the cout operation along with "<<" operator to display an output to the terminal.
To take an input we would use cin with ">>" operator.


Now let us write a simple c++ program to display Hello world on the screen.

PHP код:
#include <iostream>
using namespace std;
// main() is where program execution begins.
int main()
{
   
cout << "Hello World";// prints Hello World
   
return 0;

Simple program to read and then output a variable.

PHP код:
#include <iostream>
using namespace std;
// main() is where program execution begins.
int main()
{
    
char str[80];//create a string of size 80 to take input
       
cout << "Enter a string\n"// here \n is inputted to move the pointer to the newline, alternatively you can =use endl
    
cin>>str;
    
cout<<"You entered :"<<str<<endl;// here we use endl instead of "\n", basically they both do the same task.
   
return 0;

Reply


Messages In This Thread
[C++GDK] C++ basics. - by iSteve - 14.05.2016, 15:24
Re: [C++GDK] C++ basics. - by Micko123 - 14.05.2016, 17:12
Re: [C++GDK] C++ basics. - by Lordzy - 15.05.2016, 04:29

Forum Jump:


Users browsing this thread: 1 Guest(s)