It might be helpful for you to understand what you wrote. I'm supposing it doesn't mean what you think it does, but if there's a simple conceptual problem I can't identify it from this small sample.
// I'm continuously pushing the string
You're not pushing anything, anywhere, so I don't understand the comment.
int S = a.size()
This is missing a ;
so it won't compile. This gets the number of characters in the string a
. You are storing it in a variable of type int
, though size()
returns a size_t
. You did not define it as const
but it never changes.
set <string> s;
for(int i = 0; i < S; i++) {
s.insert(a);
}
You are inserting the string a
into the set, over and over again. That doesn't make sense, since a set doesn't store duplicates, and this has nothing to do with the individual words in a
.
I think your problem is here: You are not inserting some substring from a
each time through the loop, but a
itself. Why are you doing it S
times? Perhaps you copied code from an example that had a vector of words rather than a single string. In this code, i
is counting how many characters are in s
.
for(auto M : s) {
cout << M << endl;
}
Output each element of the set.
There's only one element; the string a
.