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

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

June 28, 2024·İbrahim Korucuoğlu
İbrahim Korucuoğlu

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\n", number);
    printf("Pi value: %.2f\n", realNumber);
    printf("Text: %s\n", text.c_str());
    return 0;
}
Last updated on