How To Read From a File in C++

In your programming journey, there will come a time when you’ll want to start working with real-world data. This kind of data is typically stored in files on disk. Since reading from files involves interacting with your operating system, it amounts to a rather complex task. In this article, we’ll look at C++ streams, file handling, and three different methods for reading data from a file into a C++ program. 

If you come from a high-level programming language like Python, reading a file into a program seems like a simple enough task. You open the file, read its contents and close it. Working with a file might take up one or two lines of your code. In C++, the workflow of reading a file is a bit more complex — there is the added step of reading to or from a stream object. To understand how our C++ programs interact with files, let us now take a look at the concept of streams in C++. 

Continue Reading

How To Print in C++

Most coding revolves around inputting data into something like an integrated development environment (IDE) to create a program that accomplishes a task. However, you’ll likely need that program to output data at some point. In this guide, we’ll look at how to print text in C++, covering ways to print a string and best format them.

What Is a String?

A C++ string is a variable that stores a sequence of characters, usually representing a word or phrase. We can call upon this variable later for use in our program by using the string command. If we’re looking to output a string, we can type the string we want to print directly into our program without first storing it as a variable. Here is an example:

Continue Reading

Fun With CSS Code Examples

Learning a new skill can be a great experience but it takes time and you have to stick with it.. Every now and then it is a great idea to sit back and have a bit of fun with the material. In this article, you will do just that with some fun CSS code examples.

Topics like how to make text bold or size an image have merits in design. As do many of the other topics covered in the Udacity CSS Content Hub. However, this post will deal with simple bits of fun you can have when learning to use HTML and CSS. 

With no goal in mind other than having a good time, get ready for some interesting CSS code examples to play around with.

Continue Reading

SQL Top Limit Fetch RowNum — Too Much Of A Good Thing

Relational databases store information in tables — tables with columns analogous to elements in a data structure and rows which are an instance of that data structure. We sometimes need to limit the number of returned rows. SQL Top, SQL Limit, SQL Fetch, and SQL RowNum (the exact syntax varies by database) are our tools in extracting the exact data we want.

In contrast to the usual behavior of the SQL Select statement, returning all relevant data, the limit function in SQL — expressed as one of Top, Limit, Fetch, or Rownum — provides a mechanism for limiting the data returned to either an absolute number or percentage of the rows. Limiting returned rows to bite-sized manageable chunks drastically reduces the storage and processing overhead requirements on software that consumes database data, resulting in a faster and more reliable code.

Rows are stored in databases at random. One adds certainty to which rows are retrieved by crafting the SQL Select statement with a winnowing WHERE clause and an ORDER BY clause. The techniques in this blog entry show how to retrieve a subset of those nicely-ordered rows, or how to iterate through those subsets across the entire results set.

Continue Reading

Creating Structured Data with JSON Objects

JSON (Javascript Object Notation) is a human-readable data format designed for easy handling within Javascript. An important data type within JSON is the JSON object, which is similar to a Javascript object but is not directly defined in the Javascript standard.

JSON objects are part of the JSON standard, which is distinct from the Javascript standard. The main difference between JSON objects and Javascript objects is that JSON objects are always static, while Javascript objects are dynamic.

In this article, we define what JSON objects are and how they differ from Javascript objects. The two data structures are similar, so it is important to understand the differences in how they are used.

Continue Reading