0
Why does this not work?
im trying to create the string library and ive ran across a problem. i cant get the operator [] to work. what im trying to this is this: example with string: string test ="test"; test[2]= 'm'; my functions are: the header file is: char& operator[](int loc); the cpp file is: char& str::operator[](int loc) { return str_real[loc]; }
1 Answer
0
Tomer Sim below is what default behavior of [] operator for string in c++:
string s = "Test";
s[2] = 'M';
cout << s; // prints TeMt
I got your point that you are trying to overload [] operator for string... correct me if my understanding is wrong.
Now what I don't understand is your expected output.. what you want as output is not clearer to me with overloaded operator



