substring for both reading and writing
Hi,
I want to define a substring that can be used for both reading and writing
but I am not complete code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
template<class Ch>
class Basic_Substring{
public:
typedef typename basic_string<Ch>::size_type size_type;
Basic_Substring (basic_string<Ch> &s, size_type i, size_type n = string::npos):ps(&s), pos(i), n(n)
{
}
Basic_Substring (basic_string<Ch>&s, const basic_string<Ch> &s2):ps(s), n(s2.length())
{
pos = ps.find(s2);
}
Basic_Substring (basic_string<Ch> &s, const Ch *p)
{
pos = ps.find(p);
}
Basic_Substring &operator =(const basic_string<Ch> &s)
{
ps->replace(pos, n, s);
return *this;
}
Basic_Substring &operator =(const Basic_Substring<Ch> &s)
{
ps = s;
return *this;
}
Basic_Substring &operator =(const Ch *p)
{
ps->replace(pos, n, p);
return *this;
}
Basic_Substring &operator =(Ch c)
{
pos = ps.find(c);
ps.replace(pos);
return *this;
}
operator basic_string<Ch>()const
{
return basic_string<Ch>(*ps, pos, n);
}
operator Ch*()const;
private:
basic_string<Ch> *ps;
size_type pos;
size_type n;
};
|
Topic archived. No new replies allowed.