sentence.cpp

来自「读取文本文件的」· C++ 代码 · 共 88 行

CPP
88
字号
// Sentence.cpp: implementation of the CSentence class.
//
//////////////////////////////////////////////////////////////////////

#include "..\headfile\Sentence.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSentence::CSentence()
{

}

CSentence::~CSentence()
{

}

CSentence::CSentence(const string &sentenceStr, int index)
{
	m_SentenceIndex = index;

	int iCurrentPos = 0;
	string Str;
	while(1)
	{
		unsigned int iPeriodPos = sentenceStr.find_first_of( ',', iCurrentPos  );
		unsigned int iExclamationPos = sentenceStr.find_first_of( ';', iCurrentPos );
		unsigned int iQueryPos = sentenceStr.find_first_of( ' ', iCurrentPos );
		unsigned int iMinPos = __min( __min( iPeriodPos, iExclamationPos ), iQueryPos );
		
		Str = sentenceStr.substr( iCurrentPos, iMinPos - iCurrentPos );
		m_WordList.push_back(Str);

		iCurrentPos = iMinPos + 1;

		if (iMinPos > sentenceStr.size())
		{
			break;
		}
	}
}

int CSentence::FindWord(const string &wordname, const int &secIndex)
{
	int i;
	int lenth = m_WordList.size();
	int num = 0;

	for (i=0; i<lenth; i++)
	{
		if (m_WordList[i] == wordname)
		{
			cout << secIndex+1<< '-' << m_SentenceIndex+1 << '-' << i+1 << endl;
			num++;
		}
	}

	return num; 
}

int CSentence::DisplayWord(map<string, int> &A)
{
	int i;
	int lenth = m_WordList.size();
	
	for (i=0; i<lenth; i++)
	{
		A[m_WordList[i]]++;
	}

	return SUCCESS;
}

int CSentence::Quit(void)
{
	m_WordList.clear();
	
	return SUCCESS;
}	

int CSentence::GetTotalWord(void)
{
	return m_WordList.size();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?