A question about print macro

Hello,
Is it possible to have print macros like the following code:

fn main() {    
          print!("{}" "{}", Varibale, Variable);
          print!("{}" , "{}", Varibale, Variable);
        }

Thank you.

print!() doesn't allow more than one format string. Why do you think you need this?

2 Likes

The print!() family of macros can evaluate other macros that appear in the format string position, so you can use things like stringify! and concat! to build it up from pieces if you need to. For example,

fn main() {
    let a = 5;
    let b = 7;
    // Same as `println!("{a} {b}", a=a, b=b)`
    println!(
        concat!(
            "{", stringify!(a), "}",
            ' ',
            "{", stringify!(b), "}",
        ),
        a=a,
        b=b,
    );
}
3 Likes

Hello,
Thank you so much for your reply.
I just wanted to know.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.