<< Back

How To Setup TextPad for Writing C++ Programs

On This Page

  1. Introduction
  2. Before You Begin
  3. Installing TextPad
  4. Adding a Blank Line
  5. Enabling Line Numbers
  6. Configuring Tab Settings
  7. Enabling Syntax Highlighting
  8. Setting the System Path
  9. Compiling C++ Programs
  10. Running C++ Programs
  11. Configuring Astyle
  12. Configuring the Documentation System
  13. Configuring Keyboard Shortcuts (Optional)

A. Introduction

This document describes how to install and configure TextPad for use with Cygwin on a Windows home computer for the course CS-11: Introduction to Programming Concepts and Methodology, C++.

TextPad is already installed on CTC and lab machines under the CIS and CS directory. You can download a copy of TextPad for evaluation at home as well. There is no charge for the download, but you must pay for the software if you decide to keep it. A single user license costs only $27 US dollars. Your instructor is a licensed user.

Note that TextPad only runs on computers using Windows. Usually both Linux and OS X (Apple) systems have good text editors already installed.

If you need more help, you can consult TextPad's Support information. Or better yet, ask a classmate if they were able to get it set up.

B. Before You Begin

These instructions assume that you have already installed Cygwin as described in the document How to Install Cygwin or How to Install Cygwin Using Babun. If you have not installed Cygwin, do so now.

C. Installing TextPad

Download TextPad and install it following the Installation Instructions. Note that there are TextPad versions 4 through 8 and these instructions have been tested on to version 7. Install the bit-size (64 or 32) of TextPad that matches your computer.

Once the installation is complete, you should configure TextPad as described below. Completing the following steps will make your programming easier.

D. Adding a Blank Line

You should have TextPad add a blank line to the end of every file to prevent the warning, "No newline at end of file", when you compile a program.

  1. Click on the Configure menu and then Preferences.

    The Preferences dialog appears with a tree on the left side.

  2. Click on Editor
  3. Check the Automatically terminate the last line of the file checkbox
  4. Press either the Apply or OK buttons.

E. Enabling Line Numbers

You should enable line numbers so you can more easily find errors reported by the compiler.

  1. Click on the Configure menu and then Preferences.

    The Preferences dialog appears with a tree on the left side.

  2. Click on View
  3. Check the Line Numbers checkbox
  4. Press either the Apply or OK buttons.

F. Configuring Tab Settings

You need to configure tab settings so that your source code files are correctly formatted and you do not loose style points on assignments.

  1. Click on the Configure menu and then Preferences.

    The Preferences dialog appears with a tree on the left side.

  2. Expand the Documents Classes by clicking on the '+' sign.
  3. Expand the C/C++ tree
  4. Click on Tabulation
  5. On the right side there should be two checkboxes labeled "Convert new tabs to spaces" and "Convert existing tabs to spaces when saving"; check both of the checkboxes.
  6. Press either the Apply or OK buttons.

G. Enabling Syntax Highlighting

You need to enable syntax highlighting so that your source code files are display in color for keywords and strings.

  1. Click on the Configure menu and then Preferences.

    The Preferences dialog appears with a tree on the left side.

  2. Expand the Documents Classes by clicking on the '+' sign.
  3. Expand the C/C++ tree
  4. Click on Syntax
  5. On the right side, check the "Enable syntax highlighting" checkbox.
  6. In the "Syntax definition file" drop down list, select "cpp.syn".
  7. Press either the Apply or OK buttons.

H. Setting the System Path

To configure Notepad++ to compile C++ using Cygwin, you must add the Cygwin bin directory to your computer's PATH environment variable. The PATH variable stores the directories where executable code is located.

Caution: Setting the path on Windows is a potentially dangerous operation and could temporarily disable your computer if done incorrectly. If you follow these instructions carefully, you and your computer will be fine. If this warning makes you too nervous, then get someone to double-check you as you perform these steps.

  1. Locate the path to the Cygwin bin directory on your computer, using Windows Explorer or another tool, and record the path. Some usual paths are:
    • Cygwin: ;C:\cygwin\bin
    • Babun Cygwin: ;C:\Users\username\.babun\cygwin\home\username

    For Babun Cygwin, the username is the login name for your computer.

  2. Open the Computer or System window by one of the following methods:
    • In the Search field, type System and select System from the list. If more than one System appears, select the one related to Control Panel.
    • Right-click on My Computer and click Properties.
    • Windows 10: Open the Control Panel, click System and Security and then click System.
    • Older Windows: Open the Control Panel and then click System

    For more help search for Windows System Properties.

  3. Open the System Properties dialog by clicking on the Advanced system settings link.
  4. In the System Properties dialog, click the Environment Variables button.
  5. In the Environment Variables dialog locate the Systems Variables section (bottom half), scroll through the list and highlight the Path variable, and then click the Edit button.

    You will see the Edit environment variable dialog or, on older Windows, the Edit System Variable dialog shown below.

  6. Add the path to the Cygwin bin to the end of the Variable list using one of the following:
    • Windows 10 (click) Click to show instructions
    • Older Windows (click) Click to show instructions

I. Compiling C++ Programs

After you have set the path, you can set up TextPad to compile programs.

  1. Click on the Configure menu and then Preferences.

    The Preferences dialog appears with a tree on the left side.

  2. Click on the Tools node of the tree.

    You will see a Tools dialog with an Add drop-down menu.

  3. Click on the Add button and then Program....

    The Select a file dialog appears.

  4. Browse to the folder in which you installed Cygwin and open the bin directory, select the g++.exe file and press the Open button.
  5. Press the Apply button.

    G++ should now appear as a choice in the Tools tree.

  6. Expand the Tools tree and click on the G++ tool.

    You should see a dialog like the following appear:

    Textpad preferences compile dialog

  7. Make sure the Command text field is like the one shown.
  8. Set the Parameters text field to be: -Wall -Wextra -Wpedantic -std=c++11 -o $BaseName $File
  9. Check the checkboxes as shown.
  10. Set the Regular expression to match output text field to:
    ^\(\(\(.[^:]\)\|\([A-Za-z]:\)\)[^:]+\):\([0-9]+\):
    For TextPad 7 and later set the regular expression to: ^(..[^:]+):(\d+):
  11. Set the Registers as shown.
  12. Click the Tools node in the tree and you will see a list of tools. (1)

    Tools dialog

  13. Click slowly two times on the G++ label on the right-hand side, which will allow you to change the tool name. (2)

    Note: do NOT click on the G++ label under Tools on the left side.

  14. Rename G++ to something like Compile C++
  15. Press the OK button.

You can now compile C++ programs by selecting Compile C++ from the Tools menu. You can test the configuration by saving the following program as hello.cpp and then compiling. Verify that the file hello.exe is created when you compile.

#include <iostream>
using namespace std;

int main() {
    cout << "Hello, World!\n";
    return 0;
}

J. Running C++ Programs

After you have set the path, you can set up TextPad to run programs after compiling with the following steps:

  1. Click on the Configure menu and then Preferences.

    The Preferences dialog appears with a tree on the left side.

  2. Click on the Tools node of the tree.

    You will see a Tools dialog with an Add drop-down menu.

  3. Click on the Add button and then DOS Command....

    The Tool dialog appears.

  4. In the Tools dialog type: cmd.exe and press the OK button
  5. Press the Apply button in the Preferences dialog.

    cmd.exe should now appear as a choice in the Tools tree.

  6. Rename the cmd.exe to Run C++ by clicking on the Tools node of the tree and then double-clicking on the cmd.exe tool.
  7. Expand the Tools tree and click on the Run C++ tool.
  8. Change the Parameters to: $BaseName
  9. Make sure the Initial folder is set to $FileDir
  10. Uncheck the Capture Output checkbox.
  11. Press the OK button.

You can now run C++ programs by selecting Run C++ from the Tools menu. Remember that you must compile the program before you try to run it.

K. Configuring Astyle

Astyle is a tool for formatting the style of your code. Artistic Style is installed with Cygwin. To configure the tool to run with TextPad, use the following instructions:

  1. Click on the Configure menu and then Preferences.

    The Preferences dialog appears with a tree on the left side.

  2. Click on the Tools node of the tree.

    You will see a Tools dialog with an Add drop-down menu.

  3. Click on the Add button and then Program....

    The Select a file dialog appears.

  4. Browse to the Cygwin bin directory (C:\cygwin\bin), select the astyle.exe file and press the Open button.
  5. Press the Apply button.

    Astyle should now appear as a choice in the Tools tree.

  6. Expand the Tools tree and click on the Astyle tool.
  7. Change the Parameters to: -A2 -s4 -p -xC80 $File
  8. Make sure the Initial folder is set to $FileDir
  9. Make sure both the Capture output and Sound alert when completed options are checked.
  10. Press the OK button.

You can now automatically style your code by selecting Astyle from the tools menu.

L. Configuring the Documentation System

Doxygen is a tool for generating API documentation in HTML format from documentation comments in source code. To configure the tool to run with TextPad, use the following instructions:

  1. Download the following files and save them anywhere in your system path. I suggest that you save them in your Cygwin directory: C:\cygwin\bin.
  2. From TextPad's Configure menu, choose Preferences.

    The Preferences dialog appears with a tree on the left side.

  3. Click on the Tools node of the tree.

    You will see a Tools dialog with an Add drop-down menu.

  4. Click on the Add button and then Program....

    The Select a file dialog appears.

  5. Browse to the bin directory of where you saved doxygen.exe, select the doxygen.exe file and press the Open button.
  6. Press the Apply button.

    Doxygen should now appear as a choice in the Tools menu.

  7. Expand the Tools menu and click on the Doxygen tool.
  8. Change the Parameters line to:

    C:\cygwin\bin\Doxyfile.cfg

    If you saved the files somewhere else, you will need to change the path shown above.

  9. Set the Regular expression to match output to:
    ^\(\(\(.[^:]\)\|\([A-Za-z]:\)\)[^:]+\):\([0-9]+\):
  10. Set the Registers as follows:
    • File: 1
    • Line: 4
  11. Check the checkbox labeled Capture output
  12. Also, check the checkbox labeled Sound alert when completed
  13. Press the OK button.

After configuring the documentation system, you should run a sample program to verify the installation works correctly. One simple program you can run is the commented version of hello.cpp shown below:

/**
 * The hello.cpp program for checking Doxygen.
 *
 * @file hello.cpp
 * @author Ed Parrish
 * @version 1.1 06/22/06
 */
#include <iostream>
using namespace std;

/**
 * The main method for the application.
 */
int main() {
    cout << "Hello, World!\n";
    return 0;
}

To test the documentation configuration:

  1. From the File menu, choose New.
  2. Copy the above program to the new document page of TextPad.
  3. From the File menu, choose Save and save the file using the name hello.cpp to a convenient location like the Desktop.
  4. From the Tools menu, choose Doxygen.

    If there are no errors or warnings, you will return to the file document: hello.cpp. If there are errors or warnings, you will see a list of them in the Command Results page of TextPad.

  5. On the Desktop, double click the html folder and find the file named: index.html.
  6. double-click the index.html file to open it in a web browser and view the generated documentation.

M. Configuring Keyboard Shortcuts (Optional)

After compiling and running programs many times, people get tired of using the menus. You can create shortcut keys for TextPad's tools to make compiling and running programs faster and easier as follows:

  1. Click on the Configure menu and then Preferences.

    The Preferences dialog appears with a tree on the left side.

  2. Click on the Keyboard node of the tree.

    You will see Categories and Commands as shown below.

  3. Select the Tools category from the list, and the tools commands will be displayed.
  4. Select the Tools command you wish to set a shortcut for.
  5. Type the keyboard shortcut combination in the "Press new shortcut key" box.

    Typically, tools are two key combinations using the Ctrl key and a number.

  6. Click the Assign button to set the shortcut.
  7. After assigning all the keyboard shortcuts, press the OK button.

TextPad shortcuts

Since I use TextPad for both Java and C++, I have set up the shortcuts as shown below:

Ctrl+1 Compile Java
Ctrl+2 Run Java Application
Ctrl+3 Run Java Applet
Ctrl+4 CheckStyle
Ctrl+5 Javadoc
Ctrl+6 Compile C++
Ctrl+7 Run C++
Ctrl+8 Astyle C++
Ctrl+9 Doxygen

<< Back