#include <math.h> float x,y,z; x=pow(y,z);This will place yz in x.
int a=10,b=12,c
c=a&b;
a= 1010
b= 1100
-------
c= 1000
int a=10,b=12,c
c=a|b;
a= 1010
b= 1100
-------
c= 1110
int a=10,b=12,c
c=a^b;
a= 1010
b= 1100
-------
c= 0110
int a=32,b;
b=a>>3;
a= 0100000
b= 0000100
int a=2,b;
b=a<<3;
a= 0000010
b= 0010000
void main()
{
int a,*p;
a=3;
cout << a << " " << &a << endl;
p=&a;
*p=4;
cout << *p << " " << &p << " " << << p << endl;
}
3 4160748428
4 4160748424 4160748428
int i=47; cout << i << " " << i + 3 << endl; Gives the correct output of: 47 50This is accomplished thru the use of multiple overloaded operator definitions.
There are defined manipulators for cout like:
| manipulator | Member function | Description |
|---|---|---|
| dec | setf(ios::dec) | Set radix to 10 |
| hex | setf(ios::hex) | Set radix to 16 |
| oct | setf(ios::oct) | Set radix to 8 |
| setfill(c) | fill(c) | Set the fill character to c. |
| setprecision(n) | precision(n) | Set display precsion to n |
| setw(n) | width(n) | Set output field width to n. |
| setiosflags(p) | setf(p) | Turn on IOS icontrol bits |
| resetiosflags(p) | unsetf(p) | Turn off IOS control bits |
| IOS::Flag | Description |
|---|---|
| skipws | Skip whitespace characters on an input stream |
| left | Left justify ouput |
| right | Right justify the output |
| internal | Left justify the sign, right justify the number |
| dec | Display the number in base 10 |
| oct | Display the number in base 8 |
| hex | Display the number in base 16 |
| showbase | Specify base ahead of the number |
| showpoint | Display floating point numbers with a decimal point |
| uppercase | Use upper case in displaying numbers |
| showpos | Show positive or negative signs |
| scientific | Output floating point in scientific notation |
| fixed | Specify the number of output to right of decimal point |
//
//
//
#include <iostream>
#include <iomanip>
using namespace std;
void main()
{
long ioflags;
ioflags=cout.flags();
int i=47;
cout << "Integer " << i << endl;
char a='a';
cout << "Character output " << a << endl;
float f=3.14159;
cout << "Floating Point " << f << endl;
cout << "Integer in hex " << hex << i << endl;
cout << "Integer in Octal " << oct << i << endl;
cout << dec;
cout << "Integer in width " << setw(5) << i << endl;
cout << "Integer in width with fill " << setfill('-') << setw(5) << i << endl;
cout.flags(ioflags);
cout.setf(ios::left);
cout << "Justify left " << setw(5) << i << endl;
cout.flags(ioflags);
cout.fill('-');
cout.setf(ios::right);
cout << "Justify Right " << setw(5) << i << endl;
i=-47;
cout.fill(' ');
cout.flags(ioflags);
cout.setf(ios::internal);
cout << "Internal " << setw(5) << i << endl;
}
Integer 47 Character output a Floating Point 3.14159 Integer in hex 2f Integer in Octal 57 Integer in width 47 Integer in width with fill ---47 Justify left 47--- Justify Right ---47 Internal -47
#include <iomanip>
#include <iostream>
using namespace std;
main()
{
char a='a';
int i=34,j=-34;
float f=3.14159;
cout << a << endl;
cout << (int)a << endl;
cout << i << " " << j << endl;
cout << (unsigned)i << " " << (unsigned)j << endl;
cout << oct << i << endl;
cout << hex << i << endl;
cout << dec;
cout << f << endl;
cout << setw(3) << i << " " << setw(3) << j << endl;
cout << setiosflags( ios:: showpoint | ios::fixed);
cout << setw(6) << setprecision(2) << f << endl;
i=8;
j=3;
cout << setw(i) << setprecision(j) << f << endl;
return(0);
}
a 97 34 -34 34 4294967262 42 22 3.14159 34 -34 3.14 3.142
#include <iostream>
using namespace std;
main()
{
char a[40];
int i,j;
float f;
cin >> a ;
cin >> i >> j;
cin >> f;
cout << a << endl;
cout <<i << " " << j << endl;
cout << f << endl;
return(0);
}
--Input file hello 3 4 3.4 --- Run the program hello 3 4 3.4
//
// File test
//
#include <iostream>
#include <fstream>
using namespace std;
void main()
{
int x =3;
float y=3.14159;
ofstream out;
out.open("testfile.txt");
out << x << endl;
out << y << endl;
out.close();
ifstream in;
in.open("testfile.txt");
in >> x;
cout << x << endl;
in >>y;
cout << y <<endl;
in.close();
}