Reputation: 171
I have a script which takes a word from input file and outputs customizated word in output file.
For example, in input file I have word ccccccaaaaaannnnndlllllleeeee
and I need to edit the word it to look like candle and output in other file. So could you please give me a example of it?
So far I have:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
string vards;
std::ifstream input_file("virkne3.in");
input_file >> vards;
std::ofstream output_file("virkne3.out");
output_file << vards.erase(std::unique(vards.begin(), vards.end()), vards.end());
cin.clear();
cin.ignore(255, '\n');
cin.get();
return 0;
}
Upvotes: 0
Views: 108
Reputation: 103733
Assuming you mean consecutive repeated letters, std::unique
does exactly that.
vards.erase(std::unique(vards.begin(), vards.end()), vards.end());
Upvotes: 3