| kemi (statz) | ![]() #2, Főfasz (2982) |
1270 | #2180 | ^ | Idézet | Sun, 11 Nov 2012 20:31:30 +01 |
| 94.21.*.* |
|
*.pool.digikabel.hu |
| Az előző modul megvalósítása ojjektumorientáltan. CStringVector.h #ifndef CSTRINGVECTOR_H_
#define CSTRINGVECTOR_H_
#include <string>
#include <vector>
using namespace std;
class CStringVector : public vector<string> {
public:
static CStringVector SplitString(string s, char delim);
string GlueVector(char delim);
long int VectorPosition(string search);
};
#endif /* CSTRINGVECTOR_H_ */CStringVector.cpp #include "CStringVector.h"
CStringVector CStringVector::SplitString(string s, char delim) {
CStringVector retval;
string sub = "";
int l = s.length();
for (int i = 0; i < l; i++) {
if (s[i] == delim) {
retval.push_back(sub);
sub = "";
} else {
sub += s[i];
}
}
retval.push_back(sub);
return retval;
}
string CStringVector::GlueVector(char delim) {
string retval = "";
long int l = this->size() - 1;
if (l > -1) {
for (int i = 0; i < l; i++) {
retval += this->at(i);
retval += delim;
}
retval += this->at(l);
}
return retval;
}
long int CStringVector::VectorPosition(string search) {
long int l = this->size();
for (long int i = 0; i < l; i++) {
if (this->at(i) == search) return i;
}
return -1;
} |