Is it possible to do something like:
string word = "Hello";
word[3] = null;
if(word[3] == null){/.../}
in C++, basically making an array element empty. For example if I wanted to remove the duplicate characters from the array I’d set them to null first and then shifted the array to the left every time I found an array index that contained null.
If this is not possible what’s a good way of doing something like this in C++ ?
This is possible, since a single element of a string is an element within a char-array and thus representable as pointer, i. e. you can retrieve the address of the element. Therefore you can set
word[3] = null. Yourif-construct is valid but the compiler prints a warning, this is becauseNULLis only a pointer constant. Alternatives would be:if (!word[3])orif(word[3] == 0).But in any case you should consider using STL algorithms for removing duplicates.