Skip to content

Instantly share code, notes, and snippets.

@decagondev
Created September 22, 2025 21:16
Show Gist options
  • Save decagondev/78a53265e214dd59ccfe51b1ac29222a to your computer and use it in GitHub Desktop.
Save decagondev/78a53265e214dd59ccfe51b1ac29222a to your computer and use it in GitHub Desktop.

Ticket 1: Implement CharToWString Helper Function

Description

Create a utility function to convert char* strings (from argv) to std::wstring. This is foundational for handling wide-character strings in Windows APIs. Test it in main() by converting sample argv-like inputs and printing them.

Acceptance Criteria

  • Function signature: std::wstring CharToWString(const char* str)
  • Handles null input gracefully (returns empty wstring).
  • Uses MultiByteToWideChar with CP_ACP.
  • In main(): Simulate argv, convert, and print to verify.

Starter Boilerplate Code

#include <windows.h>
#include <iostream>
#include <string>


/**
 * @brief Converts a null-terminated char string to a wide string (std::wstring).
 *
 * This function takes a C-style string (const char*) and converts it to a
 * wide string (std::wstring) using the system's ANSI code page (CP_ACP).
 * If the input string is null, an empty wide string is returned.
 *
 * @param str Pointer to a null-terminated C-style string to convert.
 * @return std::wstring The converted wide string.
 */
std::wstring CharToWString(const char* str) {
    // fill in the functionality
    return null;
}

int main() {
    // Test cases
    const char* test1 = "C:\\TestDir";
    const char* test2 = nullptr;
    const char* test3 = "hello world";

    std::wcout << CharToWString(test1) << std::endl;  // Expected: C:\TestDir
    std::wcout << CharToWString(test2) << std::endl;  // Expected: (empty)
    std::wcout << CharToWString(test3) << std::endl;  // Expected: hello world

    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment