简单的读写文件

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;
}
posted @ 2014-07-18 21:07  wu_overflow  阅读(104)  评论(0编辑  收藏  举报