Printing int, float and string values ​​with printf in C++

This code defines a main function where the int and float variables are constants and the text variable is not. Prints the values ​​number, realNumber, and text and then returns 0.

This code defines a main function where the int and float variables are constants and the text variable is not. Prints the values ​​number, realNumber, and text and then returns 0.

#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

int main() {
    constexpr int number = 123;
    constexpr float realNumber = 3.146;
    string text = "Hello World";
    printf("Number: %d ", number);
    printf("Pi value: %.2f ", realNumber);
    printf("Text: %s ", text.c_str());
    return 0;
}
Last modified 17.01.2025: new translations (f32b526)