Check string has unique chars only Following is my code to check if string has unique chars.

I am assuming string would have only ascii chars. 

#include &lt;iostream&gt;
#include &lt;array&gt;
using namespace std;

int main()
{
    array&lt;char,255&gt; arr;

    char *str = "ABCADEFGHIJKL";

    for (int i = 0; i &lt; 255; i++)
        arr[i] = 0;

    int i = 0;

    while (str[i])
    {
        if (arr[str[i]] == 1)
        {
            cout &lt;&lt; "Not unique";
            return 0;
        }

        arr[str[i]] = 1;

        i++;
    }

    cout &lt;&lt; "Unique";

    return 0;
}
char *str = "ABCADEFGHIJKL";



This should be const char* str because string literals are usually stored in read-only memory.


for (int i = 0; i &lt; 255; i++)
    arr[i] = 0;



You can get rid of this loop by using aggregrate initialization:

array&lt;char,255&gt; arr{};  // zero-initialize all elements



int i = 0;

while (str[i])



You can get rid of the index variable i by using the string pointer for iteration. Also use a for loop which is more concise:

for(; *str; ++str)
{
    if (arr[*str] == 1)
    {
        cout &lt;&lt; "Not unique";
        return 0;
    }

    arr[*str] = 1;
}


I would also change array&lt;char,255&gt; to array&lt;bool,255&gt; which expresses intend better as you only use values of 0 and 1 anyway. 

Edit:

As pointed out in this answer the OPs code (and mine aswell) is vulnerable to buffer overruns. Although OP stated that input will be ASCII only (which is in the range of 0..127), if the string is user input then it shouldn't be trusted. 

One way the vulnerability could be mitigated would be a range check of the input characters. If they are out of the ASCII range, discard them, replace them by a "dummy" value or do whatever fits your situation.