简单的读写文件

int main (int argc, char *argv[])
{
      string file = argv[1] ;
      cout << file;
      ofstream out (file, ofstream::app);
      string word;
      out << endl;
      while (cin >> word)
            out << word << " ";

      ifstream in (file);
      if (!in.is_open ()) {
            cout << "Cannot opening file";
            exit (-1);
      }

      string buffer;
      while (!in.eof ()) {
            getline (in, buffer);
            cout << buffer << endl;
      }
      system ("pause");
      return 0;
}

你可能感兴趣的:(写文件)