This is my CPP solution.
class Solution {
public:
string defangIPaddr(string address) {
string res;
int i = 0;
for(int i=0;i<address.size();i++){
if(address[i] == '.'){
res += "[.]";
}
else{
res.push_back(address[i]);
}
}
return res;
}
};