Posts

Showing posts from December, 2025

The Simplest Way to Read CSV Files in C++ (No Libraries Needed)

If you have ever worked with data in C++, you have likely hit a common roadblock: How do I read a CSV file? In languages like Python, this is a one-line command. In C++, however, there is no built-in read_csv function in the standard library. Most tutorials will tell you to install huge external libraries like Boost or specialized CSV parsers. But what if you just want a quick, simple solution without the hassle of managing dependencies? Pro Tip: Before you can read a file, you often need to find it first. If you need to iterate through directories or handle cross-platform file paths safely, check out my Ultimate Guide to C++17 std::filesystem . In this guide, I will show you how to read and write CSV files using only standard C++ (STL) . This solution is lightweight, portable, and perfect for simple data tasks. The Strategy: String Streams The secret to parsing CSVs efficiently in C++ lies in the <sstream> header. By treating each line of the file as a stream...

The Ultimate Guide to C++17 std::filesystem: List, Filter, and Manage Files

If you have been coding in C++ for more than a few years, you likely remember the "Dark Ages" of file manipulation. If you wanted to list the files in a directory, you had to write one implementation for Windows (using <windows.h> ), another for Linux/macOS (using <dirent.h> ), and then wrap it all in ugly preprocessor directives. It was messy, error-prone, and difficult to maintain. Enter C++17 and the std::filesystem library. This library is arguably one of the most significant quality-of-life improvements in the modern C++ standard. It provides a robust, cross-platform way to interact with the file system, manipulate paths, and iterate over directories. In this ultimate guide, we won't just list files; we will build a complete understanding of how std::filesystem works. By the end of this tutorial, you will know how to: Set up your environment for C++17. Iterate through directories efficiently. Perform recursive searches (scanning subf...