I need to write the code that will output words without repeating digits. By assignment, I have to use the char array. I decided to do this with regular expressions. At the moment I have this expression:
regex rx ("^(?!.*(.).*\1)[0-9]+$");
If you take each word of the string separately, then regex works, but if you write all the words in the string separated by a space, then regex does not work. How can i fix this?
Input file: 1234567890 987 787
The code must output at least 1234567890, because this is the first match, and it does not output anything
Full code:
int main() {
regex rx ("^(?!.*(.).*\1)[0-9]+$");
ifstream fin;
fin.open("input.txt");
int counter = 0;
char ch;
while (ch = fin.get() != EOF)
{
counter++;
}
cout << counter << "\n";
fin.close();
fin.open("input.txt");
char *str = new char [counter];
fin.getline(str, counter, '\0');
fin.close();
cmatch res;
std::regex_search(str, res, rx);
std::cout << res[0] << std::endl;
return 0;
}