CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    Sep 2000
    Location
    Indianapolis
    Posts
    6,758

    Question Proper way to print - think C++ 23+

    I'm curious -

    What is the proper way to print in a modern C++ program. Don't think about how you've aways printed with the simply using cout like this:
    Code:
    #include <iostream>
    
    int main() {
        std::string message = "The number is";
        int number = 42;
    
    
        std::cout << message << ": " << number << std::endl;
        return 0;
    }
    Rather think C++ 23. Where things like format have been added:

    Code:
    #include <iostream>#include <format>
    
    int main() {
        std::string message = "The number is";
        int number = 42;
    
        std::cout << std::format("{}: {}\n", message, number);
        return 0; }

    Or would you now do it using std::print?

    Code:
    #include <print> 
    int main() {
        int number = 42;
        std::string message = "The number is";
    
        std::print("{}: {}\n", message, number);
        return 0; }
    Or is std::print not yet fully accepted, and thus the best way is to use format?

    Again, I don't care as much about what people are doing, but rather about what people SHOULD Be doing if they are following current, modern standards.

    Thoughts?
    Last edited by Brad Jones; March 30th, 2025 at 11:20 AM.
    -----------------------------------------------
    Brad! Jones,
    Yowza Publishing
    LotsOfSoftware, LLC

    -----------------------------------------------

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured