If you want to access char* (raw c string) like an stl container this is std::experimental::string_view was invented for. But it will give an access only to read/iterate/find like operations, not modifying. There is also a sad moment - it is delayed for C++17 standard (anyway GCC-6.x already has it). See for boost::utility::string_view also. If you want to have modify access for char* I would recommend you using your own wrapper over string with length check, etc.
Here is an example I am talking about:
#include <iostream>
#include <experimental/string_view>
#include "string.h"
using namespace std;
typedef experimental::string_view string_view;
class RawStringWrapper : public string_view
{
char * sstr;
size_t len;
public:
RawStringWrapper(char * str, size_t sz)
: std::experimental::string_view(str, sz),
sstr(str),
len(sz){}
bool erase(const string &s){
auto pos = find(s);
if (std::string::npos != pos){
sstr[pos] = 0;
strcat(sstr, sstr + pos + s.size());
return true;
}
return false;
}
// ...other modifying functions you need
};
int main(int argc, char *argv[])
{
char rawString[] = "abcdefgh";
RawStringWrapper str(rawString, sizeof(rawString));
str.erase("cde");
cout << rawString << endl;
return 0;
}