============================MODULE18======================================= | | | The program examples' source codes have been arranged in the same | | order that appeared in the Tutorial. This is unedited and unverified | | compilation. Published as is basis for educational, reacretional and | | brain teaser purposes. All trademarks, copyrights and IPs, wherever | | exist, are the sole property of their respective owner and/or | | holder. Any damage or loss by using the materials presented in this | | tutorial is USER responsibility. Part or full distribution, | | reproduction and modification is granted to any body. | | Copyright 2003-2005 © Tenouk, Inc. All rights reserved. | | Distributed through http://www.tenouk.com | | | | | =========================================================================== Originally programs compiled using Borland C++. Examples compiled using VC++/VC++ .Net and gcc or g++ are given at the end of every Module. For example if you want to compile C++ codes using VC++/VC++ .Net, change the header file accordingly. Just need some modification for the header files...: ------------------------------------------------- #include //for system() #include ... { C++ codes... } ------------------------------------------------- should be changed to: ------------------------------------------------- #include //use C++ wrapper to call C functions from C++ programs... #include using namespace std; ... { C++ codes... } ------------------------------------------------- In VC++/VC++ .Net the iostream.h (header with .h) is not valid anymore. It should be C++ header, so that it comply to the standard. In older Borland C++ compiler this still works, but not proper any more... and for standard C/C++ the portability should be no problem or better you read Module23 at http://www.tenouk.com/Module23.html to get the big picture...For C codes, they still C codes :o) ========================================================================= ========================================================================= //string output using <<. For VC++/VC++ .Net change the //header files accordingly... //#include //#include //using namespace std; #include #include void main(void) { cout<<"Welcome to C++ I/O module!!!"< //for system(), if compiled in some compiler //such as Visual Studio, no need this stdlib.h #include void main(void) { int p = 3, q = 10; cout << "Concatenating using << operator.\n" <<"--------------------------------"< #include void main(void) { int p, q, r; cout << "Enter 3 integers separated by space: \n"; cin>>p>>q>>r; //the >> operator skips whitespace characters such as tabs, //blank space and newlines. When eof is encountered, zero (false) //is returned. cout<<"Sum of the "< #include void main(void) { char p; cout <<"Using member functions get(), eof() and put()\n" <<"---------------------------------------------"< #include const int SIZE = 100; void main(void) { char bufferOne[SIZE], bufferTwo[SIZE]; cout <<"Enter a line of text:"<>bufferOne; //store the string in array bufferOne //just the first word in the array string, then the //first whitespace encountered cout<<"\nThe line of text read by cin>> was:"< #include const SIZE = 100; void main(void) { char buffer[SIZE]; cout<<"Read by cin.getline(buffer, SIZE)\n" <<"--------------------------------\n" <<"Enter a line of text:"< #include const int SIZE = 100; void main(void) { char buffer[SIZE]; cout<<"Enter a line of text:"< #include #include void main(void) { int p; cout<<"Enter a decimal number:"<>p; cout< #include #include #include void main(void) { double theroot = sqrt(11.55); cout<<"Square root of 11.55 with various"< #include void main(void) { int p = 6; char string[20]; cout<<"Using field width with setw() or width()"<>string) { cout.width(p++); cout< #include #include void main(void) { cout<<"Before using the ios::showpoint flag\n" <<"------------------------------------"< #include #include void main(void) { long p = 123456789L; //L - literal data type qualifier for long... //F - float, UL unsigned integer... cout<<"The default for 10 fields is right justified:\n" < #include #include void main(void) { cout< #include #include void main(void) { long p = 30000; cout<

#include #include void main(void) { long p = 2000; cout< "< "< "< #include void main(void) { double p = 0.000654321, q = 9.8765e3; cout<<"Declared variables\n" <<"------------------\n" <<"0.000654321"<<'\n'<<"9.8765e3"<<"\n\n"; cout<<"Default format:\n" <<"---------------\n" < #include #include void main(void) { long p = 12345678; cout< #include void main(void) { long p = 2000; double q = 0.00124345; //set a new format state cout<<"The value of flags variable is: " < #include void main(void) { int p; cout<<"Before a bad input operation: \n" <<"-----------------------------\n" <<" cin.rdstate(): "<>p; cout<<"After a bad input operation: \n" <<"----------------------------\n" <<" cin.rdstate(): "< using namespace std; void main(void) { double p = 0.000654321, q = 9.8765e3; cout<<"Declared variables\n" <<"------------------\n" <<"0.000654321"<<'\n'<<"9.8765e3"<<"\n\n"; cout<<"Default format:\n" <<"---------------\n" < #include using namespace std; int main(void) { long p = 30000; cout<