1#include <cstdio>
2
3int main()
4{
5 char ch = 'a';
6 float a = 5.0, b = 3.0;
7 int x = 10;
8
9 printf("%.3f / %.3f = %.3f \n", a,b,a/b);
10 printf("Setting width %*c \n",5,ch);
11 printf("Octal equivalent of %d is %o \n",x,x);
12
13 return 0;
14}
1/* printf example */
2#include <stdio.h>
3
4int main()
5{
6 printf ("Characters: %c %c \n", 'a', 65);
7 printf ("Decimals: %d %ld\n", 1977, 650000L);
8 printf ("Preceding with blanks: %10d \n", 1977);
9 printf ("Preceding with zeros: %010d \n", 1977);
10 printf ("Some different radices: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100);
11 printf ("floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);
12 printf ("Width trick: %*d \n", 5, 10);
13 printf ("%s \n", "A string");
14 return 0;
15}
1//can't print with printf, since string is a C++ class obj and print %s
2//doesn't recognize
3//can do
4printf("%s", str.c_str()) //converts string to c str (char array)
5
6 //or just use cout<<str;
7
8 //string assignment
9 str1=str2; //or
10str1.assign(str2)