C ++ file IO sample

xiaoxiao2021-03-06  54

Article title: C The original author: querw Original: www.vczx.com Send: QUERW Publish Type: Original Release Date: 2004-10-05 Today Browse: 8 Total Views: 144

// National Day does not write, English is very bad, please concentrate on code, huh, huh :) // C Based streaming file operation makes many C turn over the programmer or choose File * // :) Actually, C flow operated documents is also very convenient to use this example is the file usage example code #pragma Warning (Disable: 4786) #include #include #include Using Namespace Std; int main () {// using std :: cout; // using std :: endl; cout << "********************* C File OPration Demo ************************ "<< endl; cout <<" using fstream or ifstream and offstream << Endl; cout << "FStream Derive from Istream and Ostream, SO Most of Method Were Defined in" << Endl; cout << "istream and ostream" << endl; cout << "by the way, i like c style /" file * / " Indeed. :) "<< endl; // input file demo cout << Endl; cout <<" **** part 1: infut file demo **** "<< endl; fstream / * ifstream * / infile; // antoher way to declare special class or function in a namespace using std :: string; string strfilename; cout << "Input in FileName:" << endl; cin >> strfilename; infile.open (strfilename.c_str (), iOS :: in / * OpenMode * /); // succeed? if (! infile) {cout << "cannot open file:" << strfilename << Endl Return 1;} // read a byte char CH1, CH2; Infile.Get (CH1); CH2 = infile.get (); // read a line // Get (char *, int max_size, char dimiliter) Can do The Same Word as getLine () // But get () Doesn't Drop the dimiliter, // use ignore () to Drop The Dimiliter (The last byte, '/ n' by default) char pszline [1024]; MEMSET Pszline, 0,1024; infile.getline (PSZLINE, 1024 / * Read count * /, '/ n' / * read untricher reach '/ n' * /);

转载请注明原文地址:https://www.9cbs.com/read-109186.html

New Post(0)