C++ 一些常用的函数以及头文件(一)

来源:互联网 发布:双色球查询软件 编辑:程序博客网 时间:2024/05/21 15:04

对需要记忆的程序进行一个罗列,以后陆续添加。



system("pause");————————————————#include <stdlib.h>

清除输入流操作:

cin.clear();
cin.sync();

在命令行中进行操作

cd/ c:\\devcpp (进入到Cpp文件路径下)
c:\devcpp>practice.exe

打开文件操作:

int main(int argc, char **argv)
{
    
if(argc<2)
{
cerr<<"No input file!"<<endl;
return EXIT_FAILURE;
}
ifstream inFile;
inFile.open(argv[1]);
if(!inFile)
{
cerr<<"can not open"<<endl;
return EXIT_FAILURE;
}

system("pause");

return o;

}

其中

ifstream& open_file(ifstream &in, const string &file) 

in.close(); // close in case it was already open 
in.clear(); // clear any existing errors 
// if the open fails, the stream will be in an invalid state 
in.open(file.c_str()); // open the file we were given 
return in; // condition state is good if open succeeded 

原创粉丝点击