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


C++ StringTokenizer::getToken方法代码示例

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


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

示例1: tokenize

//...................................................... tokenize ...
bool FileTokenizer::tokenize() {
    ifstream currentFile;             //file to be tokenized
    string inputLine;                 //line that will be read from the file
    StringTokenizer * tkn;         //String tokenizer
    int i;                            //index variable
    string token;                     //token currently extracted
    bool res = true;
    
    tkn = new StringTokenizer();
    tkn->setSeparators(currentSeparators);
    
	// [1] Initialize position and open the file to be tokenized
	tokenPos = 0;
	tokens.clear();
	currentFile.open(currentFileName.c_str(), std::ifstream::in);

	if (currentFile.fail()) {
		std::cerr << "Can't open file [" << currentFileName << "]" << std::endl;

		res = false;

	} else {
        // [2] Read input while the file has not been finished, and tokenize
        while (currentFile.good()) {
            //Get next line
            std::getline(currentFile, inputLine);

			#ifndef _WIN32
            inputLine = StringUtilities::removeAtEnd(inputLine, __CRLF);
			#endif

            //Tokenize
            tkn->setLine(inputLine);
            tkn->tokenize(true);

            /*
             * Add tokens to the token buffer.
             *
             * Tokens are added while they are "correct" tokens. A correct token is a
             * token that is not empty, does not contain "#", and does not appear
             * after a "#" character in the line.
             */
            i = 0;
            while (i < tkn->getNumTokens()) {
                token = tkn->getToken(i);

                if (token == "") {
                    //The token is blank. Do not add but check next token
                    i = i + 1;
                } else {
                    //The token is not blank, and has no comments inside it
                    tokens.push_back(token);
                    i = i + 1;
                }
            }
        }
    }

    currentFile.close();
    
    //Free memory of the ATMStringTokenizer object
    delete tkn;

    return res;
}
开发者ID:gg-uah,项目名称:GARouter,代码行数:66,代码来源:FileTokenizer.cpp


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