TextLine::TextLine(const string &text)
{
char *str, *p;
str = new char[text.size()+1];
strcpy(str, text.c_str());
p=strtok(str, " ,.!?;)");
while(p!=NULL)
{
mTokens.push_back(p);
p=strtok(NULL, " ,.!?;)");
}
delete[] str;
}
L'ho scritta così è solo che nella compilazione mi da questo errore:
..\textAnalayzer\li2TextDoc.cpp no matching function for call to `std::vector<li2::TextToken*, std::allocator<li2::TextToken*> >:ush_back(char*&)'
Guarda ti inserisco anche le due classi a cui faccio riferimento, magari ti può essere utile.
namespace li2 {
/*------------------------------------------------------------------------------
class TextToken
Rappresenta una sequenza di caratteri (token) appartenenente a una data categoria
-----------------------------------------------------------------------------*/
class TextToken {
public:
// TextToken::Type: elenco dei tipi token di interesse
enum Type {
Word, // parola
SpaceSequence, // sequenza di spazi
PunctuationMark // simbolo di punteggiatura
} ;
// TextToken::TextToken: costruttore parametrico
// permette di costruire un oggetto TextToken a partire dal tipo e dal
// valore del token
// Il valore di un token è la sequenza di caratteri che lo compongono
TextToken(Type type, const string &value)
: mTtype(type), mValue(value) {}
Type mTtype;
string mValue;
};
/*------------------------------------------------------------------------------
class TextLine
Rappresenta una linea di testo
La linea di testo è rappresentata mediante la sequenza di TextToken in essa
contenuti
-----------------------------------------------------------------------------*/
class TextLine {
public:
// TextLine::TextLine: costruttore parametrico
// Costruisce un oggetto TextLine a partire da una stringa
// L'implementazione del costruttore suddivide la stringa text nella
// sequenza di token che la compongono
TextLine(const string &text);
// costruttore di copia
TextLine(const TextLine &textline);
// distruttore
~TextLine();
// operatore di assegnazione
TextLine &operator=(const TextLine &textline);
// TextLine::getText
// restituisce il testo della linea composto a partire dalla giustapposizione dei token
// contentuti nella linea di testo
string getText();
// TextLine::getTokenCount
// restituisce il numero di token nella linea di testo
size_t getTokenCount() const;
// TextLine::getToken
// restituisce l'i-esimo token nella linea di testo
TextToken *getToken(size_t i) const;
private:
// mTokens contiene la sequenza di TextToken che compongono la linea di testo
vector<TextToken *> mTokens;
};