#include<iostream>
#include<memory.h>
#include<string.h>
using namespace std;
int main()
{
string a;
cin>>a;
int len=a.length();
bool hit[256];
memset(hit,0,sizeof(hit));
hit[a[0]]=1;
int tail=1;
for(int i=1;i<len;i++)
{
if(!hit[a[i]])
{
a[tail]=a[i];
++tail;
hit[a[i]]=true;
}
}
a[tail]='\0';
cout<<" "<<a;
}
This program removes duplicates in strings. For example an input of "aaaa"
will print only "a".
What I need to know is how to terminate the string in C++! It is not terminating with '\0'
. I read some questions on stackoverflow that indicate the termination of a string in c++ doesn't use '\0'
. I did not find how to terminate the strings instead. Can anyone help?