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

Estimated read time 1 min read

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;
}
İbrahim Korucuoğlu

Yazar, bilişim ve teknoloji alanında derlediği faydalı içerikleri bu blogta paylaşmaktadır.