Sitemap
Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Member-only story

Learning C++ with Program Templates: The Prompt, Then Read Template

--

Press enter or click to view image in full size
Photo by Jefferson Santos on Unsplash

The classic first program most people write when learning a new programming language is to output “Hello, world!” to the screen. For your first program, I’ll show you how to get output out of C++ but we’ll also learn a first program template. This template is called Prompt, Then Read and you use it to get input from the user into your program.

This article will begin, however, with some preliminaries, including how to declare and assign data to variables. Let’s get started.

C++ Variables and Data Types

A variable is an English-like name for a memory address. C++ has just a few rules for creating variables. The first rule is a variable must begin with an alphabetic character. After the first character, the other characters in a variable name can be more alphabetic characters, numbers, and the underscore. By convention, C++ variables should start with a lowercase letter.

The other thing you have to know about C++ variables is that they must be declared with a data type. The primary built-in data types you can use for variables are int (integer), double (floating-point), string (text), char (single letters), and bool (Boolean).

The combination of a data type and a variable name is called a variable declaration. A…

--

--

Mike McMillan
Mike McMillan

Written by Mike McMillan

Mike McMillan writes about technology and running.

Dev Genius
Dev Genius

Published in Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development