[Tutorial] [C++GDK] C++ basics. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (
https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] [C++GDK] C++ basics. (
/showthread.php?tid=607091)
[C++GDK] C++ basics. -
iSteve - 14.05.2016
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;
}
Re: [C++GDK] C++ basics. -
Micko123 - 14.05.2016
so you are using c++ in pawn or..??
Re: [C++GDK] C++ basics. -
Lordzy - 15.05.2016
Instead of writing basic C++ tutorials here, I suggest you to implement C++ with SA-MP GDK. There are many C++ tutorials out there if you simply search over ****** to know the basics. You can also link what to refer on your SA-MP GDK tutorials to make it more easier. Because there's really quite a lot to know about C++ for writing gamemodes using SA-MP GDK and it's best you refer them than creating separate threads.