This content is not currently approved and is visible here for review only.

Library code snippets

[C++] Simple Multiplication Test - Involves with : files & strings & arrays & ...

Note About Retrieving a File

=> If you want to retrieve a file (that contains more than one line or one line but with spaces), you can use the following code snippet :

=======================================

fstream fs( "file.dat", ios::in );

string  file; // saves the file

char    ch[81];

     

while (!fs.eof())

{

      fs.clear(ios::goodbit); // each time 'getline()' gets a line, you should call 'clear', if not, getline always gets NULL

      fs.getline(ch, 81);

      file += ch;

//    if (!fs.fail() && !fs.eof()) // indicates the end of a line

//         ;

}

 

fs.close();

============================================

Comments

  1. 01 Jan 1999 at 00:00

Leave a comment

Sign in or Join us (it's free).

Mohammad Rastkar

Want to stay in touch with what's going on? Follow us on twitter!