简单的读写文件的C++代码
//读文件一
string fileName;
std::ifstream inputFile(fileName.c_str());
if(!inputFile)
{
std::cerr << "some errors happened";
return NULL;
}
inputFile.seekg(0, ios::end); //设置文件指针到文件流的尾部
streampos ps = inputFile.tellg(); //读取文件指针的位置
cout << "File size(行): " << (ps/81) << endl;
int totalRow = ps/81;//每一行固定有81个字节
inputFile.seekg(0, ios::beg); //重新设置文件指针到文件流的头部
const int MAX=90;
char lineBuffer[MAX];
while(inputFile.getline(lineBuffer,MAX))
{
std::string readLineString(lineBuffer);
}
inputFile.close();
//读文件二
boost::filesystem::path fpath("./../InputConfig/StreamerConfig");
std::fstream filestream;
filestream.open( fpath.string().c_str());
if( !filestream.is_open() )
{
std::cerr << "can't open file \"StreamerConfig\"" << std::endl;
return false;
}
std::string st