C++对文件操作相关:
ifs.is_open() 判断文件是否打开
ifs.get() 获取文件的一个字符
ifs.good() 判断文件是否结束
std::ifstream::in 以只读的方式打开
#include <iostream>
#include <fstream> // std::ifstream
using namespace std;
int main(int argc, char *argv[])
{
std::ifstream ifs("a.cpp", std::ifstream::in);//only read
if(ifs.is_open())
{
std::cout<<"file is already open"<<endl;
}
char c = ifs.get();
while(ifs.good())
{
std::cout<<c;
c = ifs.get();
}
ifs.close();
return 0;
}