SyntaX is a lightweight, header-only C++ library designed to bring the simplicity of Python's syntax together with the raw performance of C++.
Are you tired of complex C++ boilerplate code for simple tasks? SyntaX allows you to write cleaner, more readable code without sacrificing speed. It is the perfect bridge for developers who love Python's ease of use but need C++'s execution power.
- Python-like Syntax: Familiar functions like
print(),input(), andrandint(). - Cross-Platform: Built-in support for Windows, Linux, and macOS using native APIs.
- Header-Only: No complex installation or linking required. Just drop
bettersyntax.hppinto your project. - Legacy Compiler Support: Specifically optimized to work with MinGW 6 and older environments where modern
std::threadorstd::chronomight be unstable. - Memory Efficient: Uses constant reference passing and optimized C++ streams for maximum performance.
To keep this documentation clean, we have provided a dedicated example file. You can find comprehensive usage examples covering:
- Simplified I/O (print and input)
- File Operations (read/write/append)
- Vector & Math Helpers (contains, sum, average, factorial)
- System Utilities (clear screen and sleep)
👉 Check out samples.cpp for ready-to-use code snippets!
- Download the bettersyntax.hpp file from this repository.
- Place it in your project's include directory or the root folder.
- Add #include "bettersyntax.hpp" at the top of your source code.
- Use the bettersyntax:: prefix or add using namespace bettersyntax; to start coding!
If you want to use SyntaX globally on your computer like <iostream>, follow these steps:
- Locate your compiler's include directory (e.g.,
C:\MinGW\include). - Copy
bettersyntax.hppinto that folder. - (Optional) Rename it to
bettersyntax(without the.hpp) for a cleaner look. - Now you can include it in any project using:
#include <bettersyntax>
The library is safely wrapped in the bettersyntax namespace to prevent name collisions with the standard library (std) or other third-party tools. It uses preprocessor directives to ensure stability across different Operating Systems.
| Feature | Standard C++ (STL) | SyntaX for C++ (bettersyntax) |
|---|---|---|
| Output | std::cout << x << " " << y << std::endl; |
print(x, y); |
| User Input | std::string s; std::getline(std::cin, s); |
string s = input("Name: "); |
| Random Number | min + (std::rand() % (max - min + 1)); |
randint(min, max); |
| Sleep/Wait | #ifdef _WIN32 Sleep(1000); #else usleep... |
sleep(1.0); |
| File Reading | std::ifstream, stringstream, rdbuf()... |
read_file("data.txt"); |
| Vector Search | std::find(v.begin(), v.end(), x) != v.end() |
contains(vec, x); |
| Math (Sqrt) | std::sqrt(val); |
square_root(val); |
| Clear Screen | system("cls"); or system("clear"); |
clear(); |
hypernova-developer