76 lines
1.1 KiB
C++
76 lines
1.1 KiB
C++
#include "stringlist.h"
|
|
|
|
// element am Endy anfügen
|
|
//string gelesenes_element;
|
|
//...
|
|
//dyn_array.push_back( gelesenes_element );
|
|
|
|
//Und so kannst du abschliessend auf alle Elems zugreifen:
|
|
|
|
|
|
//for( vector<string>::iterator it=dyn_array.begin(); it!=dyn_array.end();++it)
|
|
//{
|
|
//coord& elem = *it;
|
|
// ...
|
|
//}
|
|
//n = str_array.size()
|
|
|
|
std::string* CStringList::getLine(int lineId)
|
|
{
|
|
if(countLines() > lineId) return &std::string("");
|
|
|
|
return &(lines[lineId]);
|
|
}
|
|
|
|
void CStringList::addLine(std::string *line)
|
|
{
|
|
lines.push_back(*(line));
|
|
}
|
|
|
|
bool CStringList::delLine(int id)
|
|
{
|
|
return true;//lines.erase(id);
|
|
}
|
|
|
|
int CStringList::insertLine(int pos, std::string *line)
|
|
{
|
|
//dummy
|
|
return 0;
|
|
}
|
|
|
|
bool CStringList::loadFromFile(std::string *file)
|
|
{
|
|
clear();
|
|
|
|
std::ifstream in(file->c_str()); // Open for reading
|
|
|
|
std::string s;
|
|
|
|
while(getline(in, s)) // Discards newline char
|
|
addLine(&s);
|
|
|
|
return true;
|
|
}
|
|
|
|
int CStringList::countLines()
|
|
{
|
|
return int(lines.size());
|
|
}
|
|
|
|
int CStringList::countChars()
|
|
{
|
|
int result = 0;
|
|
for(int i=0;i<=int(lines.size());i++)
|
|
{
|
|
result += (int)getLine(i)->length();
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
void CStringList::clear()
|
|
{
|
|
|
|
lines.clear();
|
|
|
|
} |