当前位置: 首页>>代码示例>>C++>>正文


C++ fstream::eof方法代码示例

本文整理汇总了C++中std::fstream::eof方法的典型用法代码示例。如果您正苦于以下问题:C++ fstream::eof方法的具体用法?C++ fstream::eof怎么用?C++ fstream::eof使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::fstream的用法示例。


在下文中一共展示了fstream::eof方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetNextToken

Token Scanner::GetNextToken()
{
	Preprocess();
	if (file_.eof()){
		return Token(TokenType::TOKEN_END_OF_FILE, -1);
	}

	if (std::isdigit(cur_char_)){
		return HandleInteger();
	}
	else if (IsOperator()){
		char op = cur_char_;
		Advance();
		return Token(TokenType::TOKEN_OPERATION, op);
	}
	else if (IsLeftParam()){
		Advance();
		return Token(TokenType::TOKEN_LEFT_PARAM, '(');
	}
	else if (IsRightParam()){
		Advance();
		return Token(TokenType::TOKEN_RIGHT_PARAM, ')');
	}

	return Token();
}
开发者ID:OkabeRintarou,项目名称:syl,代码行数:26,代码来源:FAO.cpp

示例2: readNextBlock

bool PBFParser::readNextBlock(std::fstream &stream, ParserThreadData *thread_data)
{
    if (stream.eof())
    {
        return false;
    }

    if (!readPBFBlobHeader(stream, thread_data))
    {
        return false;
    }

    if (thread_data->PBFBlobHeader.type() != "OSMData")
    {
        return false;
    }

    if (!readBlob(stream, thread_data))
    {
        return false;
    }

    if (!thread_data->PBFprimitiveBlock.ParseFromArray(&(thread_data->charBuffer[0]),
                                                       thread_data->charBuffer.size()))
    {
        std::cerr << "failed to parse PrimitiveBlock" << std::endl;
        return false;
    }
    return true;
}
开发者ID:fredj,项目名称:osrm,代码行数:30,代码来源:PBFParser.cpp

示例3: Conf_Process

bool Conf_Process(std::fstream & f)
{
	char line[MAX_LINE_LENGTH];
	unsigned l = 0;
	bool breakflag = false;
	
	while (!f.eof() && !breakflag) {
		l++;
		f.getline(line, sizeof(line));
		if (line[0] == '\0') {
			// empty line, skip it (yeah we should ignore whitespaces too)
			continue;
		}
		if (line[0] == '/' && line[1] == '/') {
			// comment, skip it
			continue;
		}

		Conf_AcceptCommand(line, breakflag);
	}

	if (breakflag) {
		printf("Line: %u\n", l);
	}

	return true;
}
开发者ID:johnnycz,项目名称:qwscores,代码行数:27,代码来源:conf.cpp

示例4: readBlob

inline bool PBFParser::readBlob(std::fstream &stream, ParserThreadData *thread_data)
{
    if (stream.eof())
    {
        return false;
    }

    const int size = thread_data->PBFBlobHeader.datasize();
    if (size < 0 || size > MAX_BLOB_SIZE)
    {
        std::cerr << "[error] invalid Blob size:" << size << std::endl;
        return false;
    }

    char *data = new char[size];
    stream.read(data, sizeof(data[0]) * size);

    if (!thread_data->PBFBlob.ParseFromArray(data, size))
    {
        std::cerr << "[error] failed to parse blob" << std::endl;
        delete[] data;
        return false;
    }

    if (thread_data->PBFBlob.has_raw())
    {
        const std::string &data = thread_data->PBFBlob.raw();
        thread_data->charBuffer.clear();
        thread_data->charBuffer.resize(data.size());
        std::copy(data.begin(), data.end(), thread_data->charBuffer.begin());
    }
    else if (thread_data->PBFBlob.has_zlib_data())
    {
        if (!unpackZLIB(thread_data))
        {
            std::cerr << "[error] zlib data encountered that could not be unpacked" << std::endl;
            delete[] data;
            return false;
        }
    }
    else if (thread_data->PBFBlob.has_lzma_data())
    {
        if (!unpackLZMA(thread_data))
        {
            std::cerr << "[error] lzma data encountered that could not be unpacked" << std::endl;
        }
        delete[] data;
        return false;
    }
    else
    {
        std::cerr << "[error] Blob contains no data" << std::endl;
        delete[] data;
        return false;
    }
    delete[] data;
    return true;
}
开发者ID:fredj,项目名称:osrm,代码行数:58,代码来源:PBFParser.cpp

示例5: _WriteBlock

	void Database::_WriteBlock(Item towrite, uint64_t blockpos) {
		backing.seekg(blockpos);
		backing.seekp(blockpos);
		uint64_t blkhdrs[4];
		if (backing.eof()) {
			blkhdrs[0] = 0;
			blkhdrs[1] = towrite.itemsize;
			blkhdrs[2] = towrite.itemsize;
			blkhdrs[3] = towrite.itemsize + (sizeof(uint64_t)*4) + 1;
			backing.write(0, 1);
			backing.write((char*)&blkhdrs, sizeof(uint64_t)*4);
			backing.write(towrite.item, towrite.itemsize);
			backing.flush();
		} else {
			_GetLock(blockpos, true);
			backing.read((char*)blkhdrs, sizeof(uint64_t)*4);
			if (towrite.itemsize + 1 + (sizeof(uint64_t)*4) <= blkhdrs[3]) {
				//Block large enough or non-existent block
				backing.write(0, 1);
				blkhdrs[0] = 0;
				blkhdrs[1] = towrite.itemsize;
				blkhdrs[2] = towrite.itemsize;
				//Keep blkhdrs[3]
				backing.write((char*)&blkhdrs, sizeof(uint64_t)*4);
				backing.write(towrite.item, towrite.itemsize);
				backing.flush();
				_ReleaseLock(blockpos, true);
			} else {
				//Have to continue to a new block, allocate or reuse
				std::streampos currentpos = backing.tellp();
				backing.seekp(0, std::ios::end);
				std::streampos endpos = backing.tellp();
				backing.seekp(currentpos, std::ios::beg);
				blkhdrs[0] = (uint64_t) endpos;

				//Keep blkhdrs[1]
				blkhdrs[2] = towrite.itemsize;
				//Keep blkhdrs[3]

				uint64_t blockcancontain = blkhdrs[3] - ((sizeof(uint64_t)*4) + 1);
				backing.write(0, 1);
				backing.write((char*)&blkhdrs, sizeof(uint64_t)*4);
				backing.write(towrite.item, blockcancontain);
				backing.flush();
				_ReleaseLock(blockpos, true);

				//Continue to next block!
				Item process;
				process.itemsize = towrite.itemsize-blockcancontain;
				process.item = towrite.item+blockcancontain;
				_WriteBlock(process, blockpos);
			}
		}
	}
开发者ID:ChlorideCull,项目名称:FIDB,代码行数:54,代码来源:database.cpp

示例6: read_n_lines

// ----------------------------------------------------------------------------
int read_n_lines(std::fstream & fs, int N, StringVect & lines) {
    lines.clear();
    int K = 0;
    while (!fs.eof() && K < N) {
        std::string line;
        std::getline(fs, line);
        lines.push_back(line);
        ++K;
    }
    return K;
}
开发者ID:CaveSentinels,项目名称:SimpAmz,代码行数:12,代码来源:Proj2DataConverter.cpp

示例7: copy_file

void copy_file(std::fstream& outf, std::fstream& inf)
{
    while (true) {
        char c;
        inf.read(&c, sizeof (c));
        if(inf.eof()) {
            break;
        }
        outf.write(&c, sizeof (c));
    }
}
开发者ID:vmd90,项目名称:Trab-Multimidia,代码行数:11,代码来源:utils.cpp

示例8: leerLineaTXTGID

bool leerLineaTXTGID(std::fstream &fichero, std::string &info, std::string patron)
{
    // Buscamos la siguiente linea. Podremos encontrar cuatro cosas:
	//  - Linea en blanco: Seguimos buscando.
	//  - Linea compuesta de guiones: Seguimos buscando.
	//  - Linea de encabezado: Seguimos buscando.
	//  - Linea con patron en posiciones 2 a 12: Bingo.
	// Cualquier otra cosa encontrada, salimos devolviendo false.

    std::string linea_fichero;

    while(!fichero.eof()) {
        std::getline(fichero, linea_fichero);

        if(linea_fichero.length() < 10)
            // Linea en blanco, siguiente.
            continue;
        else if(linea_fichero.substr(2, 7).compare("-------") == 0)
            // Linea con guiones, siguiente.
            continue;
        else if(linea_fichero.substr(1, 7).compare("MARCIAL") == 0)
            // Linea de encabezado, siguiente.
            continue;
        else if(linea_fichero.substr(2, 10).compare(patron) == 0)
            // La linea que estamos buscando. Salimos.
            break;
        else
            // Lo que se haya leido no debería estar ahí. Error.
            return false;
    }

    if(!fichero.eof())
        // Almacenamos la linea en su sitio y seguimos.
        info = linea_fichero;
    else
        // Fin de fichero inesperado.
        return false;

    return true;
}
开发者ID:kbaedal,项目名称:test,代码行数:40,代码来源:cosas.cpp

示例9: extractQuotedPrefix

std::string extractQuotedPrefix(std::fstream &mfilestream)
{
    char c;
    c = getnextnonwhite(mfilestream);
    if(c!='\"')
    {
        throw parseerror::no_leading_quote;
    }
    else
    {
        mfilestream.get(c);
        std::string output;
        bool escaped = false;
        bool stringmfinished = false;

        while(!stringmfinished)
        {
            output+=c;
            if(mfilestream.eof())
            {
                throw parseerror::no_finishing_quote;
            }
            mfilestream.get(c);
            if(c=='\\')
            {
                if(escaped)
                {
                    escaped = false;
                }
                else
                {
                    escaped = true;
                }
            }
            else if(c =='\"')
            {
                if(escaped)
                {
                    escaped = false;
                }
                else stringmfinished = true;

            }
            else
            {
                escaped = false;
            }
        }
        return output;
    }
}
开发者ID:CorinnaL,项目名称:tdeditor,代码行数:51,代码来源:Parser.cpp

示例10: readHeader

BOOL AflMapData::readHeader(std::fstream& file,LPSTR pHeader,LPVOID* ppData,LPDWORD pdwSize)
{
	DWORD dwSize=0;
	if(file.eof())
		return false;
	file.read((PCHAR)&dwSize,sizeof(DWORD));
	file.read((PCHAR)pHeader,dwSize);
	file.read((PCHAR)&dwSize,sizeof(DWORD));
	*ppData = NEW BYTE[dwSize];
	file.read((PCHAR)*ppData,dwSize);
	if(pdwSize)
		*pdwSize = dwSize;
	return true;
}
开发者ID:mofon001,项目名称:AflLib,代码行数:14,代码来源:aflMap.cpp

示例11: getImageCount

    static int getImageCount(std::fstream& file_list)
    {
        int sample = 0;
        std::string line;
        while (std::getline(file_list, line))
            ++sample;
        if (file_list.eof())
            file_list.clear();  //otherwise we can't do any further I/O
        else if (file_list.bad()) {
            throw  std::runtime_error("Error occured while reading files_list.txt");
        }

        return sample;
    }
开发者ID:Jinwei1,项目名称:AirSim,代码行数:14,代码来源:StereoImageGenerator.hpp

示例12:

	Database::Database(char* file) {
		backing.open(file, std::ios::in|std::ios::out|std::ios::binary);
		if (backing.eof()) {
			char ver = FIDBVER;
			backing.write(&ver, 1);
		} else {
			char usedver = '\0';
			backing.read(&usedver, 1);
			if (usedver != FIDBVER) {
				std::cerr << "Version " << usedver << " in file differs from " << FIDBVER << " in library!" << std::endl;
				return;
			}
		}
		indexstore = _ReadIndex(1); //Index is always on second byte
	}
开发者ID:ChlorideCull,项目名称:FIDB,代码行数:15,代码来源:database.cpp

示例13: readPBFBlobHeader

inline bool PBFParser::readPBFBlobHeader(std::fstream &stream, ParserThreadData *thread_data)
{
    int size(0);
    stream.read((char *)&size, sizeof(int));
    size = SwapEndian(size);
    if (stream.eof())
    {
        return false;
    }
    if (size > MAX_BLOB_HEADER_SIZE || size < 0)
    {
        return false;
    }
    char *data = new char[size];
    stream.read(data, size * sizeof(data[0]));

    bool dataSuccessfullyParsed = (thread_data->PBFBlobHeader).ParseFromArray(data, size);
    delete[] data;
    return dataSuccessfullyParsed;
}
开发者ID:fredj,项目名称:osrm,代码行数:20,代码来源:PBFParser.cpp

示例14: calculateTransform

void calculateTransform(std::fstream &pointsFs) {
    Eigen::Matrix4f trans;
    pcl::PointCloud<pcl::PointXYZ> points_in_kinect;
    pcl::PointCloud<pcl::PointXYZ> points_in_arm;

    //read data from file into data structures
    char temp_buf[200];
    pcl::PointXYZ KinPos;
    pcl::PointXYZ ArmPos;
    while(true){
        pointsFs.getline(temp_buf,200);
        if(pointsFs.eof()) break;
        if (sscanf(temp_buf,"%f,%f,%f,%f,%f,%f", &(KinPos.x), 
                   &(KinPos.y), &(KinPos.z), &(ArmPos.x), &(ArmPos.y), 
                   &(ArmPos.z)) == 6) {
            points_in_kinect.push_back(KinPos);
            points_in_arm.push_back(ArmPos);
        }
    }

    //calibrate
    pcl::registration::TransformationEstimationSVD<pcl::PointXYZ,pcl::PointXYZ> transformation_estimator;
    if(points_in_kinect.size() > 6 ) {
        transformation_estimator.estimateRigidTransformation(points_in_kinect,points_in_arm,trans);
        cout << "Calculated transformation: " <<endl;
        cout << trans << endl;
        //write to file
        std::ofstream fs("mat.txt");
        if(!fs){
            std::cerr<<"Cannot open the output file."<<std::endl;
        }
        else{
            fs<< trans << endl ;
            fs.close();
        }
        cout << "transformation matrix written to mat.txt " << endl;
    }
    else{
        cout << "Not enough points to run SVD estimation" << endl;
    }
}
开发者ID:CARRTUSF,项目名称:baxter_kinect_calibration,代码行数:41,代码来源:main.cpp

示例15: ReadLine

////////////////////////////////////////////////////////////////////////////////////
///
///   \brief Reads a line from a fstream adding it to a string, reading up
///          to a newline character.
///
///   \param[in] str File stream operator.
///   \param[out] line Line read from file (doesn't include carriage return).
///
///   \return Number of characters read.
///
////////////////////////////////////////////////////////////////////////////////////
unsigned int FileIO::ReadLine(std::fstream& str,
                              std::string& line)
{
    char ch;
    line.reserve(512);
    line.clear();
    while(str.eof() == false && str.good())
    {
        str.get(ch);
        if(ch == '\n')
        {
            break;
        }
        else
        {
            line.push_back(ch);
        }
    }

    return (unsigned int)line.size();
}
开发者ID:ShowLove,项目名称:Robotics_Club,代码行数:32,代码来源:fileio.cpp


注:本文中的std::fstream::eof方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。