Need help with string

Implement an algorithm to determine if a string has all unique characters. The user will enters a sentence and your job is to determine if there is repeating letter in the sentence.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <sting>

using namespace std; 

int main()
{
	bool isUnique(string);

int main(){
    bool uniq;
    string a;
    cout << "Please input a string, not a very long one...."<< endl;
    getline(cin, a);
    uniq = isUnique(a);
    if (uniq == true)
        {
            cout << "The string has no repeatations." <<endl;
        }else{
            cout << "The characters in the string are not unique." <<endl;
        }
    return EXIT_SUCCESS;


}

bool isUnique(string str){

int len = strlen(str);
bool uniq = true;

for (int i = 0; i <= len; ++i)
    {
        for (int j = i+1; j <= len; ++j)
        {
            if (str[j] == str[i])
            {
                uniq = false;
            }
        }
    }
return uniq;
	string char;
	cout << " Please enter a string of characters: "
	getline(cin,char)


		

I need help on making a nested loop and remove all the spaces in the string using erase function from string class. Also, I want to know if there are better soulution?
Last edited on
Simplest way is to add a check within the for-i loop to skip if str[i] is space

Otherwise I remember there is a replace function in boost - string which you can use to replace space by empty char.
Topic archived. No new replies allowed.