Skip to main content

Python-iostream

Python-iostream is a Python library that provides C++ style input/output streams (cin and cout), making it easier for C++ programmers to transition to Python or for anyone who prefers the C++ I/O syntax.

Features

  • C++ style I/O operations: Use cout << for output and cin >> for input
  • Formatting manipulators: Support for endl, hex, dec, oct similar to C++
  • Type conversion: Automatic type conversion for input values
  • Convenient input variables: Create variables that can be directly used with cin >>
  • Operator overloading: Full support for arithmetic operations with input variables

Installation

You can install python-iostream using pip:

pip install python-iostream

Quick Start

Here's a simple example showing how to use the library:

from iostream import cout, cin, endl, hex, dec, oct, var

# Output examples
cout << "Hello, World!" << endl
cout << "Integer: " << 42 << endl
cout << "Hexadecimal: " << hex << 42 << dec << endl  # Hexadecimal output
cout << "Octal: " << oct << 42 << dec << endl        # Octal output

# Input examples
name = var("")
age = var(0)

cout << "Enter your name: "
cin >> name  # No assignment needed, just like C++
cout << "Hello, " << name << "!" << endl

cout << "Enter your age: "
cin >> age
cout << "You are " << age << " years old."
cout << " In 10 years, you will be " << (age + 10) << " years old." << endl

# Reading multiple values
numbers = [0, 0, 0]
cout << "Enter three numbers: "
cin >> numbers
cout << "You entered: " << numbers[0] << ", " << numbers[1] << ", " << numbers[2] << endl

Detailed Usage

Output with cout

The cout object provides a C++ style output stream:

cout << "Text" << endl  # Output text followed by a newline
cout << 42 << " is the answer" << endl  # Mix different types
cout << hex << 255 << dec  # Output in hexadecimal (then switch back to decimal)

Input with cin and var()

Use the var() function to create variables that can be directly used with cin >>:

# Create input variables with default values
name = var("")  # String variable
age = var(0)    # Integer variable
pi = var(0.0)   # Float variable

# Read input into variables
cin >> name
cin >> age
cin >> pi

Formatting Manipulators

The library provides several formatting manipulators similar to C++:

  • endl: Output a newline and flush the buffer
  • hex: Switch to hexadecimal output for integers
  • dec: Switch to decimal output for integers (default)
  • oct: Switch to octal output for integers
cout << "Decimal: " << 42 << endl
cout << "Hexadecimal: " << hex << 42 << dec << endl
cout << "Octal: " << oct << 42 << dec << endl

Reading Multiple Values

You can read multiple values into a list:

values = [0, 0, 0]  # Pre-allocate a list of 3 integers
cout << "Enter three numbers: "
cin >> values  # Will read up to 3 values from input

Arithmetic Operations with Input Variables

Input variables created with var() support standard arithmetic operations:

num1 = var(0)
num2 = var(0)

cin >> num1
cin >> num2

cout << num1 << " + " << num2 << " = " << (num1 + num2) << endl
cout << num1 << " - " << num2 << " = " << (num1 - num2) << endl
cout << num1 << " * " << num2 << " = " << (num1 * num2) << endl
cout << num1 << " / " << num2 << " = " << (num1 / num2) << endl

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for cppio 1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cppio 1.1
File Size Uploaded Provenance Actions
cppio-1.1.tar.gz 3.5 kB Without provenance Details for cppio-1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cppio 1.1
File Interpreter ABI Platform Actions
cppio-1.1-py3-none-any.whl Python 3 none any Details for cppio-1.1-py3-none-any.whl

Total release size: 6.8 kB

Release files / cppio-1.1.tar.gz

Download URL cppio-1.1.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
14847f28345cbe8defb664962eb427a1d6b23bd9fbf7a133f07323406117a262
BLAKE2b-256 checksum
How to use checksums
3289509a925fb51ab4fd3cc531e9f9dadf2b3e7fe3be5067fa9766395ed4be6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.0

Release files / cppio-1.1-py3-none-any.whl

Download URL cppio-1.1-py3-none-any.whl
Size 3.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
26a294885c84b770ae9222ce91d2af3babe37be734b70de0e5aa47dab8ad99d8
BLAKE2b-256 checksum
How to use checksums
eb3a2130d60a258dead59acd785a4dd9d851603274d80db56b3e22de8f95327b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.0

Security for cppio 1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page