User input/output is a key component in the programs you write, yet most online tutorials just provide a quick-and-dirty method of grabbing data. In other words, it works right up until the point the user does something unexpected. In this tutorial you will learn how to avoid the common mistakes by doing it properly. Take this typical method that tutorials use to teach user input: [code=cplusplus] int number; cin >> number; cout << "You typed the number " << number << ".\n";[/code] Now let's say you want the user to enter a string that contains a space in it. Since …

Member Avatar
Member Avatar
+11 forum 25

# Introduction # A recurring problem many newcomers face when tackling C++ is the compilation process, from sources to binaries. This tutorial will detail that process. It will be especially useful for people only familiar with higher-level languages (if any), but veterans of one or more native languages (C, Fortran, C++, D, etc.) might still learn a thing or two. And to that point, I would also mention that conceptually, most of this tutorial applies to any native, compiled language. For widest applicability, this tutorial will feature GNU tools (GCC) used in a Unix-like environment (POSIX). For Mac OSX, the …

Member Avatar
Member Avatar
+11 forum 2

Yesterday i completed my exercises on loop , that's why today i've decided to create a tutorial on loop in c++. # Loop # loop allows us to repeat a statement or a group of statements. When we want to repeat a single statement then it is not necessary to put curly braces But if we want to repeat a group of statements then it must be enclosed with curly braces. And it is a good practise to enclosed your loop body with curly braces. c++ has three loop control structures while loop do-while loop for loop # while loop …

Member Avatar
Member Avatar
+7 forum 15

This tutorial is the first time I write about coding techniques for improving the performance of software. This is going to be a step-by-step journey through a real example, with real benchmark results at every step so that you can see the effect of the different optimization techniques. And as my first tutorial on performance optimization, I have to talk about the most important principle in performance optimization: keeping things hot. If you expect this tutorial to be about showing bits of code and the assembly listings generated by the compiler and then, showing how to reduce the number of …

Member Avatar
Member Avatar
+7 forum 3

As usual, after learning new stuff, I write on it. Yesterday I finished learning on "Functions in C++" and found that functions are very easy to learn and useful. Hope this tutorial helps beginners. # What is function? # Sometimes when we want to execute a specific task wherever it's needed, instead of writing the entire code again, we should create a block of code that is called a function. Once you define the functionality inside the function body, you can call it whenever and wherever it's needed. Functions prevent code repetition. There are 2 terminologies: 1. Defining a function: …

Member Avatar
Member Avatar
+2 forum 11

File I/O With C++ Fstream **Intro** File handling is as simple as writing in a book, much easier to modify and find. It's so simple people get confused with it :-). Welcome to the world of file handling. We will use the c++ fstream classes to do our file handling. So, what is a file? A file is just a bunch of bytes stored on a hardisk. Some have a specific structure others dont. Files are used to save info so that it can be retrived later for use. [I dont think you will want to save 100 people's address …

Member Avatar
Member Avatar
+5 forum 53

# Tutorial On Operators# *Operators are the signs to the tell the compiler to perform specific task*. The Operators fall into following categories :- Arithmatic Operator Relational Operator Logical Operator Bitwise Operator Miscellaneous Operator(i added Assignment Operators in this categeory) **Arithmatic operators:-** There are following arithmetic operators:- + Add [6+2=8] - Subtract [6-2=4] * Multiply [6*2=12] / Divide [6/2=3] % Modulus(Reminder) [7%2=1] **Relational Operator :-** Relational Operators are used to compare 2 values and result in true [1] or false [0]. < less than > greater than <= less than equal to >= greater than equal to == equal to …

Member Avatar
Member Avatar
+5 forum 10

##Why Use Arrays?## Let's begin by considering why arrays might be needed. What is the problem that this feature solves? How does it make your life as a programmer easier? When studying new features, it's important to recognize what that feature does for you and where the incentive is in using it. Otherwise you might learn a feature just because it's there, but never actually use it, or never learn it at all. Fortunately, arrays are very easy to justify. Consider a small program that collects 5 names and displays them to the user: #include <iostream> #include <string> using namespace …

Member Avatar
Member Avatar
+4 forum 11

Following up on a discussion on [this thread](http://www.daniweb.com/software-development/cpp/threads/470519/looping-using-recursion/), I did some tests on the performance of recursion vs. iteration, and some interesting things happened, so I thought I would share the results. I'm gonna structure this a bit like a lab-report, because that's really the best way to put it. But I hope the discussion can continue on additional ideas or insight into the performance issues that are discussed here, or if you disagree with my analysis. ## Experimental Method ## So, I took Schol-R-LEA's coin-combination example as a test case, and timed the execution of three different versions: recursive, …

Member Avatar
Member Avatar
+4 forum 6

# Introduction # The subject of this tutorial is a bit more advanced than the subjects I have tackled in the past, but I hope this will find some interested readers. From time to time in C++, programmers find themselves torn apart between using a *Generic Programming* style which primarily involves the use of templates and compile-time mechanisms (e.g., STL), and using a *Object-Oriented Programming* style that often favors inheritance and run-time dispatching mechanisms (e.g., Qt). As it is so often the case, there is no obvious "winner", i.e., there is no paradigm that should always be preferred, even within …

Member Avatar
+2 forum 0

[B]Beginner's guide to C++0x: Avoiding Memory Problems by Design of Ownership[/B] If you ever read any resources on C++ programming or object-oriented programming, you must have heard some rethorics like "inheritance is for the [I]is a[/I] relation, composition is for the [I]has a[/I] relation". Is that all? Is that the end of the story? What is the underlying motivation for this dichotomy? What if my case fits neither category? The point of this tutorial is to answer those questions and show how to translate the answers into real C++0x code. This tutorial is really about thinking about the relationships between …

Member Avatar
Member Avatar
+8 forum 2

[B]Beginner's Guide to C++0x: The Big Five - Implementing a Resource-holding RAII Class[/B] This tutorial will show how to implement a [I]resource-holding class[/I] showing practical use of [I]C++0x features[/I]. A resource-holding class is any class which holds, with its data members, a resource which could include: [LIST] [*]dynamically allocated memory [*]an internet connection socket [*]a file stream [*]any other handle to an operating system resource (e.g. window or thread handle), or [*]an opaque pointer from an external library. [/LIST] The main characteristic of a resource-holding class is the requirement to allocate (or create) the resource (capturing a handle or pointer …

Member Avatar
+17 forum 0

The End.