C++C++11C++14C++17Learn C++

Tutorial: Learn To Sort A Text File On Windows With C++

This Is How Trivial Copy Constructors Work In A C++ App

In C++ Builder sorting text string lines is very easy by setting Sorted property of a StringList to true. This example below sorts a given text file and saves as sorted in same name.

Sorting a Text File with a Console VCL Application

  1. Create a new C++ Builder Console VCL project, Save all unit and project files into a folder. modify lines as below

2. Hit F9 or press Run button to run your code.

That’s All.

Sorting a Text File with a Console FMX Application

If you want to develop on MutliDevice platforms you must create FireMonkey Project. You can do as same here in C++ Builder FMX Console Project, as below;
1. Create a new C++ Builder Console FMX project, Save all unit and project files into a folder. modify lines as below

2. Hit F9 or press Run button to run your code.

Sorting a Text File with a GUI based FMX or VCL Visual Application

If you want to use GUIs (Like Buttons, Memos, Edits, etc.) we can use OpenDialog component and a OnClick() event of a Button.

1. Create a new C++ Builder Console FMX or VCL project, Save all unit and project files into a folder. modify lines as below

2. Drag OpenDialog component on to form and a Button. Double click to button to create OnClick() event and modify it as below.

3. Add our sort_textfile() procedure above these lines or in public declarations of TForm in Unit1.h
4. Hit F9 or press Run button to run your code.

Note that file format should be in *.txt form and it will be modified after used.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20

What Is The Stack (std::stack) In Modern C++?

C++C++11C++14C++17C++20Learn C++

What Is The Queue (std::queue) In Modern C++?

C++C++11C++14C++17Learn C++SyntaxTemplates

What Are The Logical Operation Metafunctions In Modern C++?

C++C++14C++17C++20Learn C++

What Are The Deprecated C++14 Features In C++17?