Forums
New posts
Search forums
News
Security News
Technology News
Giveaways
Giveaways, Promotions and Contests
Discounts & Deals
Reviews
Users Reviews
Video Reviews
Support
Windows Malware Removal Help & Support
Inactive Support Threads
Mac Malware Removal Help & Support
Mobile Malware Removal Help & Support
Blog
Log in
Register
What's new
Search
Search titles only
By:
Search titles only
By:
Reply to thread
Menu
Install the app
Install
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Forums
Security
Guides - Privacy & Security Tips
C++ tutorial (Malwareup)
Message
<blockquote data-quote="new user" data-source="post: 14444" data-attributes="member: 376"><p>Here is a tutorial I have created on Malwareup. It is a stick in the Programming/Coding Discussion over there. I might as well post it here. </p><p></p><p>Original Thread: http://malwareup.org/viewtopic.php?f=40&t=2068</p><p>MalwareUp Programming Board (Check this out if you are interested in Programming): http://malwareup.org/viewforum.php?f=40</p><p></p><p></p><p>Below this line, it is copy and pasted from MalwareUp</p><p>------------------------------------------------------------</p><p>I am going to start a Basic tutorial Series for C++.</p><p>It will begin with Just Hello World, but unlike other tutorials I will explain what every Line of Code does.</p><p>Writing/using code you don't know is frankly, stupid and lazy.</p><p></p><p></p><p>I will be assuming you are using the QT SDK. On Linux any C++ IDE(or a plain text editor if you know what you are doing) will do. On Windows/OSX, use QT SDK.</p><p>QT is a Language Framework. It has libraries and code you can re-use (under terms of LGPL). There are lots of stuff added upon normal C++ (if you include relevant headers). QT Projects Only Compile in QT SDK (well I think, it uses gcc and qmake, you probably can without the sdk but for non-linux users its best to avoid compiling outside the SDK). If you are using QT libraries and functions.</p><p></p><p>Do not use Visual C++; it is alright for certain Windows specific cases, but for the most part stay away from visual anything.</p><p>http://qt.nokia.com/</p><p>There are many links at the end that you may want to check out.</p><p></p><p></p><p><span style="font-size: 18px"><strong>Capitals make a difference in your code, cout and COUT are completely different!</strong></span></p><p></p><p><strong>Linux only:</strong></p><p><strong><u><span style="font-size: 18px">Terminal Commands also are affected by capitals, su and SU are not the same!</span></u></strong></p><p>If you use a Debian/Ubuntu system, run this command first:</p><p>[code]sudo apt-get install build-essential[/code] (For other distros, if this package does not exist, look for gcc and gdb)</p><p>Then get the SDK (do not get from package manager, may be outdated), http://qt.nokia.com/</p><p>To run the .bin file, right click, go to properties, and on the permissions tab check the box to make it executable. Then open a terminal, cd into the directory of the file and type:</p><p>[code]./NameOfFileGoesHereCapitalLettersMatter.bin[/code]</p><p>Go through the install.</p><p><strong>End Linux Only</strong></p><p></p><p>On Windows/OSX just double click the installer.</p><p></p><p>Make sure your system is fully up-to-date.</p><p></p><p>Lets begin.</p><p></p><p>If you are using QT, make sure you have a folder named projects somewhere. This is where all your programming stuff will go.</p><p></p><p>Open QT Creator. At the start, you get a welcome screen, under the QT logo You have 3 tabs: Getting Started, Develop, and News&Support.</p><p>Leave News&Support. On the Develop Tab you have a list of Your recent projects, you can click on them to load.</p><p>What we want to do is click New Project. In the Pop-Up, choose QT C++ Application. Then QT Console Application. Hit the Choose Button. For the name we will call it "projectOne" (remove quotes). For the Create In part, navigate to the Projects folder you made earlier. Check the Box to use as default. Hit next. On this part, leave add to version control and the other option as <none> and hit Finish. You will get a Popup about the QT version. You should only have one Option under desktop that is checked. Hit Finish.</p><p></p><p>You will be taken to a Window Showing some code.</p><p>[code]</p><p>#include <QtCore/QCoreApplication></p><p></p><p>int main(int argc, char *argv[])</p><p>{</p><p> QCoreApplication a(argc, argv);</p><p></p><p> return a.exec();</p><p>}</p><p>[/code]</p><p></p><p>Delete all of that code.</p><p></p><p>Put this in instead:</p><p>[code]</p><p>#include <iostream></p><p>//This is a Comment In your Code</p><p>/*This</p><p>is also a different type of comment</p><p>*/</p><p>using namespace std;</p><p>int main ()</p><p>{</p><p> cout << "Hello World!"<< endl;</p><p> cout << "Press Enter to Continue" << endl;</p><p> cin.ignore();</p><p> cin.get();</p><p> return 0;</p><p>}//end main</p><p>[/code]</p><p></p><p>Compile (Build) the program (hammer symbol).</p><p></p><p>When it is done, <u>do not run it</u> (run is green arrow).</p><p></p><p>The Compiler has given you a binary. Now go to that projects folder we made. There will be two more folders inside it.</p><p>One will the whatever your project name is.</p><p>The other will be called nameofproject-build-desktop</p><p>Go inside the nameofproject-build-desktop</p><p>There will be 3 files. They are: main.o, Makefile, projectname</p><p>The file that is your project name is an executable.</p><p>On windows Double click. On linux, because it is a console app, open a terminal and navigate to directory. Run [code]./filename[/code].</p><p>You will get Hello World! on your screen, and be asked to press enter to continue. Do so.</p><p>Now we could have run this app from the green arrow in qt creator, but Qt has issues and bugs with console applications, since it does not open a console, but run it within the IDE.</p><p>Now you can exit out of the Project Folder.</p><p></p><p>You have successfully built your first C++ program!</p><p>Now here is were the real purpose of my tutorial kicks in.</p><p>What did all that code mean?</p><p></p><p>Lets go over it line-by-line.</p><p></p><p>[code]#include <iostream>[/code]</p><p>That Includes the iostream header file. Header files are files that contain functions and other tools for the language.</p><p>For example: cin.get(); is a function</p><p>exit(0); is a function, it is not used here,but you will get a compiler error without including the cstdlib header!</p><p>You can right your own functions, but some functions that look simple are many many lines of code. A header file is basically a file containing a bunch of functions written for you. You even write your own headers!</p><p></p><p>Now the next couple of lines are special.</p><p>They are comments.</p><p>Comments are notes, or information you write, that do not affect the program.</p><p>In QT, comments are coloured green.</p><p>Everything after // for <u>that one line</u> is a comment</p><p>Everything after /* is a comment, <u>for the whole program</u>, until you end it with */</p><p></p><p></p><p>[code]using namespace std;[/code]</p><p>Here is the best explanation I could find:</p><p></p><p>Found that here: http://forums.devshed.com/showpost.php?p=193617&postcount=2</p><p></p><p>[code]int main()[/code]</p><p>and [code]return 0;[/code] (I know return 0; is at the end)</p><p>Starts the main function. Main is a function found in every program, it is the main part of the program.</p><p>int is the function return type. At the end of a function, a value is returned. int means integer, the return (return 0; at the end) is an integer. The return value can indicate different things. return 0; indicates to the OS that the execution ended successfully.</p><p></p><p>[code]{[/code] Beginning of a Code Block. End is [code]}[/code]</p><p>Code Blocks are chunks of code. We will get into this more later. Eventually you will be using multiple code blocks.</p><p></p><p>[code]cout << "Hello World!"<< endl;[/code]</p><p>cout is a stream used to display output to the default location. (Console).</p><p>After cout we put << and then what we want to output in quotes "". Then we put << endl; The endl; clears the stream, well get into that later, but it also functions like pressing enter in a text editor.</p><p></p><p>[code]cin.ignore();[/code]</p><p>I do not want to go into detail. But later we will be taking input and storing them in variables. When the user press the enter key, some times that enter key is "picked up" by the cin.get(); we use to "pause" or stop the program. This gets rid of that. It is just good habit to put it before cin.get();</p><p></p><p></p><p>[code]cin.get();[/code]</p><p>This grabs input. Much like the cin statement we will later use. Since we are putting no arguments, it will not do anything with the input that is given. Just a handy way of pausing, since the program will stop to wait for input.</p><p></p><p></p><p>[code]return 0;[/code]</p><p>Already covered.</p><p>Go to where int main() is covered.</p><p></p><p></p><p>Thanks For Reading Part One!</p><p></p><p><strong>Tips:</strong></p><p>Never use:</p><p>[code]void main()[/code]</p><p>Instead of that use [code]int main()[/code]</p><p>void main() is non-standard, only microsoft's compiler even allows it!</p><p></p><p>Never use: [code]system("pause");[/code]</p><p>It is non-portable. Only works on windows. The cout << "Press Enter" << endl; and cin.get(); lines accomplish what that does. </p><p></p><p><strong>Other Resources:</strong></p><p></p><p>http://developer.qt.nokia.com/</p><p>http://doc.qt.nokia.com/latest/tutorials.html</p><p>http://www.cplusplus.com/doc/tutorial/</p></blockquote><p></p>
[QUOTE="new user, post: 14444, member: 376"] Here is a tutorial I have created on Malwareup. It is a stick in the Programming/Coding Discussion over there. I might as well post it here. Original Thread: http://malwareup.org/viewtopic.php?f=40&t=2068 MalwareUp Programming Board (Check this out if you are interested in Programming): http://malwareup.org/viewforum.php?f=40 Below this line, it is copy and pasted from MalwareUp ------------------------------------------------------------ I am going to start a Basic tutorial Series for C++. It will begin with Just Hello World, but unlike other tutorials I will explain what every Line of Code does. Writing/using code you don't know is frankly, stupid and lazy. I will be assuming you are using the QT SDK. On Linux any C++ IDE(or a plain text editor if you know what you are doing) will do. On Windows/OSX, use QT SDK. QT is a Language Framework. It has libraries and code you can re-use (under terms of LGPL). There are lots of stuff added upon normal C++ (if you include relevant headers). QT Projects Only Compile in QT SDK (well I think, it uses gcc and qmake, you probably can without the sdk but for non-linux users its best to avoid compiling outside the SDK). If you are using QT libraries and functions. Do not use Visual C++; it is alright for certain Windows specific cases, but for the most part stay away from visual anything. http://qt.nokia.com/ There are many links at the end that you may want to check out. [SIZE=5][b]Capitals make a difference in your code, cout and COUT are completely different![/b][/SIZE] [b]Linux only:[/b] [b][u][SIZE=5]Terminal Commands also are affected by capitals, su and SU are not the same![/SIZE][/u][/b] If you use a Debian/Ubuntu system, run this command first: [code]sudo apt-get install build-essential[/code] (For other distros, if this package does not exist, look for gcc and gdb) Then get the SDK (do not get from package manager, may be outdated), http://qt.nokia.com/ To run the .bin file, right click, go to properties, and on the permissions tab check the box to make it executable. Then open a terminal, cd into the directory of the file and type: [code]./NameOfFileGoesHereCapitalLettersMatter.bin[/code] Go through the install. [b]End Linux Only[/b] On Windows/OSX just double click the installer. Make sure your system is fully up-to-date. Lets begin. If you are using QT, make sure you have a folder named projects somewhere. This is where all your programming stuff will go. Open QT Creator. At the start, you get a welcome screen, under the QT logo You have 3 tabs: Getting Started, Develop, and News&Support. Leave News&Support. On the Develop Tab you have a list of Your recent projects, you can click on them to load. What we want to do is click New Project. In the Pop-Up, choose QT C++ Application. Then QT Console Application. Hit the Choose Button. For the name we will call it "projectOne" (remove quotes). For the Create In part, navigate to the Projects folder you made earlier. Check the Box to use as default. Hit next. On this part, leave add to version control and the other option as <none> and hit Finish. You will get a Popup about the QT version. You should only have one Option under desktop that is checked. Hit Finish. You will be taken to a Window Showing some code. [code] #include <QtCore/QCoreApplication> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); return a.exec(); } [/code] Delete all of that code. Put this in instead: [code] #include <iostream> //This is a Comment In your Code /*This is also a different type of comment */ using namespace std; int main () { cout << "Hello World!"<< endl; cout << "Press Enter to Continue" << endl; cin.ignore(); cin.get(); return 0; }//end main [/code] Compile (Build) the program (hammer symbol). When it is done, [u]do not run it[/u] (run is green arrow). The Compiler has given you a binary. Now go to that projects folder we made. There will be two more folders inside it. One will the whatever your project name is. The other will be called nameofproject-build-desktop Go inside the nameofproject-build-desktop There will be 3 files. They are: main.o, Makefile, projectname The file that is your project name is an executable. On windows Double click. On linux, because it is a console app, open a terminal and navigate to directory. Run [code]./filename[/code]. You will get Hello World! on your screen, and be asked to press enter to continue. Do so. Now we could have run this app from the green arrow in qt creator, but Qt has issues and bugs with console applications, since it does not open a console, but run it within the IDE. Now you can exit out of the Project Folder. You have successfully built your first C++ program! Now here is were the real purpose of my tutorial kicks in. What did all that code mean? Lets go over it line-by-line. [code]#include <iostream>[/code] That Includes the iostream header file. Header files are files that contain functions and other tools for the language. For example: cin.get(); is a function exit(0); is a function, it is not used here,but you will get a compiler error without including the cstdlib header! You can right your own functions, but some functions that look simple are many many lines of code. A header file is basically a file containing a bunch of functions written for you. You even write your own headers! Now the next couple of lines are special. They are comments. Comments are notes, or information you write, that do not affect the program. In QT, comments are coloured green. Everything after // for [u]that one line[/u] is a comment Everything after /* is a comment, [u]for the whole program[/u], until you end it with */ [code]using namespace std;[/code] Here is the best explanation I could find: Found that here: http://forums.devshed.com/showpost.php?p=193617&postcount=2 [code]int main()[/code] and [code]return 0;[/code] (I know return 0; is at the end) Starts the main function. Main is a function found in every program, it is the main part of the program. int is the function return type. At the end of a function, a value is returned. int means integer, the return (return 0; at the end) is an integer. The return value can indicate different things. return 0; indicates to the OS that the execution ended successfully. [code]{[/code] Beginning of a Code Block. End is [code]}[/code] Code Blocks are chunks of code. We will get into this more later. Eventually you will be using multiple code blocks. [code]cout << "Hello World!"<< endl;[/code] cout is a stream used to display output to the default location. (Console). After cout we put << and then what we want to output in quotes "". Then we put << endl; The endl; clears the stream, well get into that later, but it also functions like pressing enter in a text editor. [code]cin.ignore();[/code] I do not want to go into detail. But later we will be taking input and storing them in variables. When the user press the enter key, some times that enter key is "picked up" by the cin.get(); we use to "pause" or stop the program. This gets rid of that. It is just good habit to put it before cin.get(); [code]cin.get();[/code] This grabs input. Much like the cin statement we will later use. Since we are putting no arguments, it will not do anything with the input that is given. Just a handy way of pausing, since the program will stop to wait for input. [code]return 0;[/code] Already covered. Go to where int main() is covered. Thanks For Reading Part One! [b]Tips:[/b] Never use: [code]void main()[/code] Instead of that use [code]int main()[/code] void main() is non-standard, only microsoft's compiler even allows it! Never use: [code]system("pause");[/code] It is non-portable. Only works on windows. The cout << "Press Enter" << endl; and cin.get(); lines accomplish what that does. [b]Other Resources:[/b] http://developer.qt.nokia.com/ http://doc.qt.nokia.com/latest/tutorials.html http://www.cplusplus.com/doc/tutorial/ [/QUOTE]
Insert quotes…
Verification
Post reply
Top