Tuesday, July 24, 2012

program to Remove duplicate character from a string


//this program uses the function of string library

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string str1 = "silicon ABC ADC BCA";
    string str2;
    int pos;


    for(int i = 0; i < str1.length(); i++)
    {
        if( (pos = str2.find(str1[i])) < 0)
            str2 += str1[i];
    }


    cout << str2 << endl;
    return 0;
}


OUPUT:

No comments:

Post a Comment