xxxxxxxxxx
//can't print with printf, since string is a C++ class obj and print %s
//doesn't recognize
//can do
printf("%s", str.c_str()) //converts string to c str (char array)
//or just use cout<<str;
//string assignment
str1=str2; //or
str1.assign(str2)
xxxxxxxxxx
#include <cstdio>
int main(){
char c = 'S';
float x = 7.0, y = 9.0;
double d = 6.548;
int i = 50;
printf("The float division is : %.3f / %.3f = %.3f \n", x,y,x/y);
printf("The double value is : %.4f \n", d);
printf("Setting the width of c : %*c \n",3,c);
printf("The octal equivalent of %d is %o \n",i,i);
printf("The hex equivalent of %d is %x \n",i,i);
return 0;
}
xxxxxxxxxx
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
/*
printf() function is declared under the <cstdio> header file.
*/
// Example 1: integer format printf().
int num1, num2;
printf("Enter Number 1: \n");
cin >> num1;
printf("Enter Number 2: \n");
cin >> num2;
printf("Results = %d \n", num1 + num2);
//*******************************************************************************
// Example 2: float or double format printf().
float n1, n2;
printf("Enter Number 1: \n");
cin >> n1;
printf("Enter Number 2: \n");
cin >> n2;
printf("Results = %f \n", n1 + n2);
//*******************************************************************************
// Example 3: float or double format printf().
char ch[] = "Array of char";
printf("Ouput is %s \n", ch);
return 0;
}