try it, then you know it____________just do it , as love easily fade.

一次只有一个目标,步子迈小些,抑制一次实现所有功能的冲动。 过程如何结果就如何,行动是欢喜的,不管是兴奋还是沮丧的情绪都对结果无益。贵在持之以恒

导航

c++ 输入流

open file

ifstream in;

in.open("input.txt");  //parameter is uchar*! just correspond with the main parameter, argv[1].

ifstream& openFile(ifstream& inf, const char* pN)
{
    inf.close();        //close flow
    inf.clear();        //clear any existing error
    //combine inf and file, open file.
    inf.open( pN );

    return inf;    
}
ifstream& openFile(ifstream& inf, const string& pN)
{
    inf.close();        //close flow
    inf.clear();        //clear any existing error
    //combine inf and file, open file.
    inf.open( pN.c_str());    //!!must convers string into uchar*

    return inf;    
}    

如果文件打开成功,则上述函数返回值(inf)有效。 同cin

if(!openFile( ......) )

//文件打开没有成功, 终止允许。

————————————————————————————————————

2 cin

 cin.clear();   //使得输入流有效   
 cin.sync();   //清空输入流缓冲中无效的数据   // it is a must


posted on 2013-03-23 20:08  吾一  阅读(257)  评论(0编辑  收藏  举报